November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
You can read more about it here http://marekblotny.blogspot.se/2009/02/episerver-5-r2-and-link-collection.html
ToMappedLink() gives you the whole link, if you only want the url I guess you can do something like;
public static string ToMappedUrl(this LinkItem link)
{
var url = new UrlBuilder(link.Href);
if (PermanentLinkMapStore.ToMapped(url))
{
return url.ToString();
}
return link.Href;
}
Ah... That looks like a method that would solve the whole thing... I've tried to implement the extension but I'm having some problems and I get complaints when I compile. I'm kind of new to EPi so if you could show me an example on how to implement the method (in code behind) I would be grateful! Thanks...
I got it to work... I missed importing the extension from markup and I was also sending the wrong type (Href) to the method. When using LinkItem and importing extension it worked like a charm :) Many thanks!
Hi,
I am also getting stuck with same scenario after createing linkcollection of documents type(PDF Type), In case of repeater it shows the different url which lookes like a GUID type url and its not navigating to the pdf cdoc which i have save from the episerver,
can you please tell me the code how to get the href of uploaded pdf doc file from the linkcollection by using method ToMappedUrl(). I am using episerver 6 version.
I solved it by using an extension class for the method (same as above):
public static class UrlExtension
{
public static string ToMappedUrl(this LinkItem link)
{
var url = new UrlBuilder(link.Href);
if (PermanentLinkMapStore.ToMapped(url))
{
return url.ToString();
}
return link.Href;
}
}
And then by calling it from markup (and importing the namespace for the extension):
<%@ import Namespace="yournamespace.Templates.Public.Units.LinkCollectionUrlExtension" %>
... and in a repeater adding ...
<a href="<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).ToMappedUrl() %>" target="<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Target %>"
title="<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Title %>">
<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Text %>
</a>
Everything is fine but i dont have the unit LinkCollectionUrlExtension, so code is not working and can not map tomappedurl method on href.
where i can find this LinkCollectionUrlExtension? Please tell me...
Nishant you have to import the namespace where you put ToMapped() extension method. Hg El's code was just an example.
Nishant you have to import the namespace where you put ToMapped() extension method. Hg El's code was just an example.
Hi,
Is it possible to add a LinkItem to the page with parameter in query string?
I create an "external link" with Url to some page (http://www.mysite/Page_A?someId=1) and add it to my LinkItemCollection, but when I save and publish my changes - this link is converted from external to internal, and there is no query parameter anymore.
Can somebody help with this?
Thanx
Additional query string parameters should be kept, even though the link is converted to an internal one. Which version are you running on?
We use EPiServer 7.7.1.0;
Sorry, parameter (from query string) is kept, it is only not visible for Editor.
But still, there is another problem:
We have our custom route registered: "club/{clubId}/{language}/{node}/{partial}/{action}". When I create an external link to the page using this route - (for example, "http://mysite/club/15/somePage" - link is converted to internal ("http://mysite/somepage"), and parameter disappears (I have subscribed to the DataFactory.Instance.PublishedPage event, and I see that when I publish page - link is already converted to internal)
Btw, it looks like problems come from database: when I use my local database - link is not converted to external, and all works fine, but when I use database backup from our Development stand - it doesn't work.
Hi!
You are correct that we don't store additional path information after the part that is used to address a content item, only additional query string information. Also, you are correct that the UI does not show these values when editing the link again. We are discussing how to handle this internally since we've got some feedback in this area. However, the solutions we have discussed are not that simple to implement so we need to find out the best way to handle this. Ideally, we would present this as an external link but still have support for permanent links in the backend so that links does not get broken just because the URL to an item is changed.
We have our custom route registered: "club/{clubId}/{language}/{node}/{partial}/{action}". When I create an external link to the page using this route - (for example, "http://mysite/club/15/somePage" - link is converted to internal ("http://mysite/somepage"), and parameter disappears (I have subscribed to the DataFactory.Instance.PublishedPage event, and I see that when I publish page - link is already converted to internal)
Ok, for now this problem can be fixed with using HttpModule instead of routing
Hi!
I just talked to the team and they plan to start investigating a possible fix for this now. So if we are lucky, this might be released within a few weeks if the fix is reasonable to implement.
Hi!
I've run into a little problem with LinkCollection. I've searched the forum and think I've found a solution for cms 6 (using GetMappedHref()) but I'm stuck with cms 5 here. My code works just fine for adding external links (http://test.com) but once I point to a local/internal page I get the long guid type of link (~/link/2f3f05692d04468a8c33f815ff2ca12c.aspx). It all works when I render the list via <EPiServer:Property PropertyName="TPLC" runat="server" /> in the markup code. But this option doesnt give me the possibilty to style the list the way I want to... So I'm using an asp:repeater to handle this. I databind the collection from code behind:
links = CurrentPage.Property["TPLC"].Value as LinkItemCollection;
linkRepeater.DataSource = links;
linkRepeater.DataBind();
and in markup I use:
<asp:Repeaterrunat="server" ID="linkRepeater">
<HeaderTemplate><ol></HeaderTemplate>
<ItemTemplate>
<li><ahref="<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Href %>"target="<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Target %>"title="<%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Title %>"><%# (Container.DataItem as EPiServer.SpecializedProperties.LinkItem).Text %></li></a>
</ItemTemplate>
<FooterTemplate></ol></FooterTemplate>
</asp:Repeater>
As I said, it works just fine for external links but how do I convert the internal guid links to a usable link that works?
The function will mainly be used for external links but incase someone decides to go internal I need the compability. I've googled and found some tips but nothing small and "simple"... Seems like there should be some kind of simple solution for this. Thankful for any tips!