0

I have an own UI for discussion messages. The issue is the Url of the actual SPListItem doesn't help:

SPListItem message = //get message
var url = message.Url; //returns "/Lists/forum/hello/2.000"

What I want is the url "http://contoso/Lists/forum/Flat.aspx?RootFolder=/Lists/forum/hello&CTID=xxx"

This is what I get when I go to a discussion thread.

2

The CTID is the ContentTypeId from the listitem and the rootfolder is ServerUrl from the listitem.

Try this code to see if it gives you the url you want. You could also dynamically get the viewurl if you desire.

var url = "http://contoso/Lists/forum/Flat.aspx?RootFolder=" + message["FileDirRef"] + "&CTID=" + message["ContentTypeId"];
  • Can I get "contoso/Lists/forum" generically? – Anatoly Mironov Sep 13 '11 at 13:58
  • I get ...Flat.aspx?RootFolder=/Lists/forum/hello /2.000 &CTID=xxx2 And therefore I get 404 error – Anatoly Mironov Sep 13 '11 at 14:09
  • thank you very much Steve. You gave me a awesome hint. Here is the version that I have tested and it really works: var url = message["FileDirRef"] + "?Flat.aspx?RootFolder=" + message["FileDirRef"] + "&CTID=" + message["ContentTypeId"]; Could you update your code in your answer? – Anatoly Mironov Sep 13 '11 at 14:17
  • Or var url = SPUrlUtility.CombineUrl(argument.List.ParentWeb.Site.Url, message["FileDirRef"] + "?Flat.aspx?RootFolder=" + message["FileDirRef"] + "&CTID=" + message["ContentTypeId"]); – Anatoly Mironov Sep 13 '11 at 14:29
  • I'm glad you got it working. Yes you can get it generically. From the views collection or calling the defaultviewurl property of the splist. – Steve Lineberry Sep 13 '11 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.