Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取指向sharepoint的任何给定路径的GUID_Sharepoint_Api_Guid - Fatal编程技术网

获取指向sharepoint的任何给定路径的GUID

获取指向sharepoint的任何给定路径的GUID,sharepoint,api,guid,Sharepoint,Api,Guid,我正在尝试获取给定sharepoint URL的GUID。我不介意使用API、Web服务或Sharepoint的数据库 如果我要写一个函数,它的签名是: //从路径获取GUID。 字符串GetGuidFromPath(字符串路径){} 我有一个线索:SPContentMapProvider,但它似乎没有得到正确的信息 谢谢大家! 取决于-当前请求的上下文是什么?您的代码是否在SharePoint请求的上下文中运行?如果是这样,您可以使用SPContext.Current.Web.ID 否则,您的

我正在尝试获取给定sharepoint URL的GUID。我不介意使用API、Web服务或Sharepoint的数据库

如果我要写一个函数,它的签名是: //从路径获取GUID。 字符串GetGuidFromPath(字符串路径){}

我有一个线索:SPContentMapProvider,但它似乎没有得到正确的信息


谢谢大家!

取决于-当前请求的上下文是什么?您的代码是否在SharePoint请求的上下文中运行?如果是这样,您可以使用
SPContext.Current.Web.ID

否则,您的代码是否至少在其中一个SharePoint服务器上运行?如果是这样,您需要使用:

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

取决于-当前请求的上下文是什么?您的代码是否在SharePoint请求的上下文中运行?如果是这样,您可以使用
SPContext.Current.Web.ID

否则,您的代码是否至少在其中一个SharePoint服务器上运行?如果是这样,您需要使用:

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

谢谢你的回答,假设我的URL是这样的:或者:哪一个是相同的页面(具有不同的视图)我将如何使用上述代码?非常感谢。谢谢你的回答,假设我的URL是这样的:或者:哪一个是相同的页面(具有不同的视图)我将如何使用上述代码?非常感谢。