SPListItem.URL Funky Return Fiesta
Man, I have never seen this before, but doing a simple SPListItem.URL and returning the URL returns a funky ass value. It looks like hex or some crap, like this:
http://localhost/lists/MyList/6_.000
What the hell is that? Shouldn't the SPListItem.Url property return the actual URL to the item?
To get around this, you have to tailor your code a little bit differently.
-
SPList list = site.Lists.GetList("MyList");
-
-
SPListItem item = list.Items[id];
-
-
list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url + "?ID=" + item.ID
Now you will actual retrieve the correct path to the DispForm.aspx page.
Wierd, eh?
13 Comments »
RSS feed for comments on this post. TrackBack URL





















Articles & Research
SharePoint Architecture
Personal/Off-Topic
Latest Free SharePoint Software
SecureCenter For SharePoint
SharePoint Security Assurance Program™
Free Online SharePoint Security Tools
Online SharePoint Security Health Assessment
Article Or Research Filed Under 
Man that is so weird!
Comment by Stacy Draper — August 28, 2007 @ 6:39 am
In fact this property works only for Doc items …
Comment by Renaud Comte — August 28, 2007 @ 9:01 am
That, I didn’t know. Thanks for the tip Renaud!
Comment by Adam Buenz — August 28, 2007 @ 10:34 am
[...] Man, I have never seen this before, but doing a simple SPListItem.URL and returning the URL returns a funky ass value. It looks like hex or some crap, like this: http://localhost/lists/MyList/6_.000 What the hell is that? Shouldn't the SPListItem Read More……(read more) [...]
Pingback by Blogger Loser » Blog Archive » SPListItem.URL Funky Return Fiesta — August 28, 2007 @ 2:06 pm
[...] SPListItem.URL Funky Return Fiesta [...]
Pingback by Links (8/28/2007) « Steve Pietrek’s SharePoint Stuff — August 28, 2007 @ 5:24 pm
Interestingly enough, the List.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url code returns someting fishy for me too:
I get http://tabeokaser001/test_menno/Pages/Lists/TEST/DispForm.aspx, while the correct url is http://tabeokaser001/test_menno/Lists/TEST/DispForm.aspx?ID=1 (without ‘Pages’).
I think I’ll fiddle with PAGETYPE.PAGE_DISPLAYFORM some more, and see what I can come up with.
Comment by Menno — August 30, 2007 @ 5:04 am
Well part of that makes sense, you should get that unless you are appending the + “?ID=” + item.ID so that it is aware of which SPListItem ID to point to. The other part, where it is truncated “Pages” out of the name, I don’t know where it comes from.
I have also noticed that sometimes it does not work on custom list types, which is weird, because it should. If you can post back your results it would be appreciated!
Comment by Adam Buenz — August 30, 2007 @ 6:01 am
Hi, thx it helped me out.
Worked with my custom list but I had to change it a bit to not get the /Pages/ before.
myList.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl + “?ID=” + myItem.ID
Comment by Djavan ROA — March 11, 2008 @ 8:44 am
coolio, just what i was looking for.
Comment by Hal Diggs — October 8, 2008 @ 3:33 pm
Seems to work for me. Might some people be getting problems with the Url if they’re using a customer display form? In which case the form might be stored inside the pages list.
I’m just guessing here. I’ve not used customer display forms yet.
Comment by Daniel Revell — March 18, 2009 @ 7:02 am
[...] http://www.sharepointsecurity.com/sharepoint/sharepoint-development/splistitemurl-funky-return-fiest... [...]
Pingback by SPListItem Url | blog.richardramdat.com — September 29, 2009 @ 9:38 pm
Hi,
Not sure if this helps anyone at this point, but depending on whether or not the default dispform has been changed for the list item’s content type, this might help resolve the proper display form.
Once you have the list item, you can get the content type of the item and check the DisplayFormUrl before using the PAGE_DISPLAYFORM. For example,
SPListItem listItem = list.GetItemById( itemId );
SPContentType contentType = listItem.ContentType;
string urlToItem = type.DisplayFormUrl;
if(String.IsNullOrEmpty(urlToItem))
Comment by Robert Beard — December 7, 2009 @ 10:56 pm
Great tip Robert!
Comment by adam — December 8, 2009 @ 6:46 am