Tuesday, January 20, 2009

Sitecore 6 C# snippets including item URL


Sitecore.Context.Item the requested URL's target item.

Get the URL for an item

string urlOfItem = Sitecore.Links.LinkManager.GetItemUrl(item);

string currentItemUrl = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item);

Get the full URL for an item

Sitecore.Links.UrlOptions urlOptions = Sitecore.Links.LinkManager.GetDefaultUrlOptions(); 
urlOptions.AlwaysIncludeServerUrl = false;
string currentItemUrl = Sitecore.Links.LinkManager.GetItemUrl(sample,urlOptions);

Get an items field value

string fieldValue = item["fieldname"];
FieldRenderer.Render(item, "fieldname");


Sitecore.Collections.ChildList children = item.GetChildren(ChildListOptions.None);

No comments:

Post a Comment