Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create link to Sitecore Item

Tags:

I know I have done this before but I can't seem to remember where or how.

I want to create a link to an Item in Sitecore. This code:

Sitecore.Data.Items.Item itm = Sitecore.Context.Database.GetItem(someID); return itm.Paths.Path.ToString(); 

Produces the following string:

http://localhost/sitecore/content/Home/Item1/Item11/thisItem 

I would like to have this string instead:

http://localhost/Item1/Item11/thisItem.aspx 

What is the correct way to get the path to the item? In this case I can't use a normal Sitecore link:

Sitecore.Web.UI.WebControls.Link 
like image 516
Zooking Avatar asked Mar 23 '09 17:03

Zooking


People also ask

How do I link an item in Sitecore?

Go to your site's Extras folder. Right click the LinkItems folder and select Insert > Link Item.

How do you add a link to a field?

Right-click in the Link field in the record for which you want to create a hyperlink. Point to Hyperlink and select Edit Hyperlink. To remove a hyperlink, right-click the linked text in the field, point to Hyperlink and select Remove Hyperlink.

How do I add an anchor link in Sitecore?

In the Experience Editor or the Content Editor, navigate to the item where you want to insert an anchor. Open the Rich Text Editor and select the text or image that you want make an anchor. In the Hyperlink Manager dialog, click the Anchor tab and in the Name field, enter a unique name for the anchor. Click OK.


1 Answers

You're needing this one, assuming you're running Sitecore v6 or anything more recent (tested with 8.2-6, should work with 9 too):

Sitecore.Links.LinkManager.GetItemUrl(item); 
like image 200
Mark Cassidy Avatar answered Nov 15 '22 16:11

Mark Cassidy