开发者

Getting the GUID for any given path to sharepoint

开发者 https://www.devze.com 2022-12-28 05:51 出处:网络
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.

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消