Monday, 30 May 2011

Get an SPListItem from a raw URL

How to get an SPListItem from a raw url?


As easy as this:



using (SPSite site = new SPSite(url))

{

using (SPWeb webToSearch = site.OpenWeb())

{

SPListItem pageToLook = webToSearch.GetListItem(url);

}

}







OpenWeb() will open your Web at the current location given by the url in new SPSite(url).



Cheers