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'm using FullTextSqlQuery to search items on specific list. Query returns results properly. Now I'd like to get SPListItem from search results. As I searched Internet, I found couple of examples, but they all are based on document libraries - getting file and associated with that file SPListItem.

My results contain path to item in such format:

https://<site>/<web>/Lists/<list>/DispForm.aspx?ID=5

I tried to use SPWeb's method GetListItem(path) with server relative url from above path, but returned item is null

So is there any way to get SPListItem from list based on item path returned from search results?

share|improve this question
    
what you're actually trying to do –  Muhammad Raja Dec 28 '12 at 12:15
    
I want to obtain SPListItem from given search result. Search query is written so it returns results from only one list, and I'd like to get those items. –  jjczopek Dec 28 '12 at 12:22

1 Answer 1

Try getting the SPListItem by the ID provided in the URL.

For example if you have this URL: https://<site>/<web>/Lists/<list>/DispForm.aspx?ID=5 the ID of the item is 5. So you can use the SPList.GetItemById() method and pass the item ID as argument.

EDIT:

There is another way to get the SPListItem by using the SPWeb.GetFile() with the owsItemUrl value as argument. After you get the SPFile object you can use the SPFile.Item property to get the SPListItem.

Example:

If the FullTextSqlQuery is called query:

ResultTableCollection result = query.Execute();
DataTable dt = new DataTable();
if (result.Count > 0)
{
    using (ResultTable relevantResults = result[ResultType.RelevantResults])
    {
        dt.Load(relevantResults, LoadOption.OverwriteChanges);
        foreach (DataRow row in dt.Rows)
        {
            if (row["ContentType"].ToString() == "Item")
            {
                using (SPSite lookupSite = new SPSite(row["owsItemUrl"].ToString()))
                {
                    using (SPWeb web = lookupSite.OpenWeb())
                    {
                        SPFile file = web.GetFile(row["owsItemUrl"].ToString());
                        SPListItem spListItem = file.Item;

                    }
                }
            }
        }
    }
}
share|improve this answer
    
This the think I'd like to avoid, but in the end it might be only solution. –  jjczopek Dec 28 '12 at 12:24
    
@jjczopek Plese try my new edits, maybe that will help. –  user3470 Dec 28 '12 at 13:14
    
I can't add owsItemUrl to my query, because it throws error. Same thing when I add ContentType. :/ –  jjczopek Dec 28 '12 at 13:55
    
You can use my first suggestion or try my answer to your other question: sharepoint.stackexchange.com/questions/54826/… –  user3470 Dec 28 '12 at 14:21

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.