Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
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 3

How about the SPWeb.GetListItem method?

It takes in the server relative or absolute URL and returns a SPListItem object.

share|improve this answer

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);
}
}
share|improve this answer
1  
to 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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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