Tuesday, August 11, 2009

Get SPFile or SPListItem from URL

By request: this is the code I'm using to retrieve a SPFile object from an URL. You can get the SPListitem with SPFile.Item.
     protected SPFile GetSPFile(string url)
{
using(SPSite site = new SPSite(url))
{
using(SPWeb web = site.OpenWeb())
{
SPFile file = web.GetFile(url);
return file;
}
}
}

1 comment:

  1. Thanks for sharing this. If you might have any problems with adoption sharepoint, a sharepoint consultant may help you..

    ReplyDelete