I have a FullTextSqlQuery that is returning the URL for a list item. I would like to create a new SPListItem object from that URL. Is there an easy way to do this, or will I need to peel apart the URL to determine the site/list/listitem?
Asked
Active
Viewed 1.1k times
2
-
I can't imagine there would be any other way than to dissect the URL so that you can get the list. Like SPList list = web.GeList("/Lists/ListPath/"); It's only able to return the full URL? – Robert Kaucher Mar 13 '12 at 18:57
3 Answers
2
How about the SPWeb.GetListItem method?
It takes in the server relative or absolute URL and returns a SPListItem object.
Vardhaman Deshpande
- 10,462
- 1
- 26
- 52
0
Try this (not verified)
using(spsite site = new spsite(url))
{
using(spweb web = site.openweb())
{
string itemurl = url.replace(web.url, "");
itemurl = web.serverrelativeurl + itemurl;
splistitem item = web.getlistitem(itemurl);
}
}
sssreddy
- 4,473
- 2
- 22
- 38
-
2to add: they have a great method in SharePoint, SPUtility.ConcatUrls, which allows to assure your urls are combined correctly. it would be a good practice to use it every time you concatenate urls :) – Andrey Markeev Mar 13 '12 at 20:29
-
I don't think that is what he means... It seems he has a full URL for 1 item and he wants to create a new SPItem with that other item's URL. – Robert Kaucher Mar 13 '12 at 23:10
0
Seems that the SPWeb.GetListItem method doesn't work with list elements but only with files..
I have the same problem, I tried this way:
How to get an SPListItem from a Search Query Programmatically
It works but I think it's a little inefficent.