Create link to Sitecore Item

Zooking picture Zooking · Mar 23, 2009 · Viewed 8.3k times · Source

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

Answer

Mark Cassidy picture Mark Cassidy · Mar 23, 2009

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);