0

I have trouble generating the url using

string.Format("/sitecore/shell/Applications/Content%20Manager/default.aspx?id={0}&la={1}&fo={0}",contentItem.ID, contentItem.Language) 

This generates something like a path to the item but not an actual url that redirects to the content. Am I missing any settings? I really appreciate any help.

Thanks.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Newbie
  • 361
  • 2
  • 15
  • 33
  • Can you clarify what you are trying to achieve? The code snippet indicates that you are working inside the content editor, and you have tagged the question with 'email-notifications', but your question doesn't mention either. – Martin Davies Oct 14 '14 at 22:18
  • Answered here: http://stackoverflow.com/questions/674308/create-link-to-sitecore-item/675101#675101 – Mark Cassidy Oct 15 '14 at 09:01

3 Answers3

0

If its a media item which you want URL of

   Database master = Sitecore.Configuration.Factory.GetDatabase ("master");
    Item item = master.GetItem ("/sitecore/media library/Images/XXX");
    If (item! = null)
    {
        MediaItem mediaItem = new MediaItem (item);
        img.ImageUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl (mediaItem);
    }

If its a content item you can simply append the path like http://{yoursite}/{path relative to home item}

  • thanks.. i am actually trying to send a link to content in email notifications.In the workflow if a user submits content an email will be sent to approvers with a link to the item. I tried string.Format("/sitecore/shell/Applications/Content%20Manager/default.aspx?id={0}&la={1}&fo={0}",contentItem.ID, contentItem.Language) but this generated a path to the item but not a link..can you provide an example for generating content link..sorry if this is a basic question..jus started with sitecore.. – Newbie Oct 15 '14 at 20:58
  • how do i append http://devsite.com/ before the path that is generated? i tried Sitecore.Context.Site.Hostname..returns nothing – Newbie Oct 15 '14 at 21:27
0

In addition to the answer provided by Mark you can try the following to get the full server URL that includes the domain:

UrlOptions urlOptions = new UrlOptions();
urlOptions.AlwaysIncludeServerUrl = true;
LinkManager.GetItemUrl(item, urlOptions);
Varun Nehra
  • 379
  • 1
  • 5
0

I haven't understood what exactly you are trying to achieve. But if you want a URL of an item then I think you can use the following:

Sitecore.Links.LinkManager.GetItemUrl(item);