I'm trying to get the GUID of a given sharepoint URL. I don't mind using the API or the webservices or Sharepoint's database.
if i were to write a function, it's signature would be: //get a GUID from path. string 开发者_StackOverflow中文版GetGuidFromPath(string path){}
I had a lead: SPContentMapProvider but it doesn't seem to get the right info.
Thank you!
Depends - what's the context of the current request? Is your code running in the context of a SharePoint request? If so you can just use SPContext.Current.Web.ID
Otherwise, is your code at least running on one of the SharePoint servers? If so you'll need to use:
// Given the URL http://mysharepointsite.com/sites/somesite/somesubsite
using(SPSite site = new SPSite("http://mysharepointsite.com/sites/somesite"))
{
using(SPWeb web = site.OpenWeb("somesubsite"))
{
Guid webId = web.ID;
}
// Or
Guid rootWebId = site.RootWeb.ID;
}
精彩评论