Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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:如何确定一个真实URL是否可用或已被网站使用_Sharepoint_Url_Moss - Fatal编程技术网

Sharepoint:如何确定一个真实URL是否可用或已被网站使用

Sharepoint:如何确定一个真实URL是否可用或已被网站使用,sharepoint,url,moss,Sharepoint,Url,Moss,我如何确定URL是否可用并可用于在网站集中创建新网站,或者它是否已被其他网站、列表或库使用 假设相对URL“/newUrl/”尚未使用,在您尝试访问SPWeb的任何属性之前,以下代码实际上不会引发异常 using(SPSite site = new Site("http://portal/")) { SPWeb web = site.OpenWeb("/newUrl/"); // no exception string title = web.Title; // t

我如何确定URL是否可用并可用于在网站集中创建新网站,或者它是否已被其他网站、列表或库使用

假设相对URL“/newUrl/”尚未使用,在您尝试访问SPWeb的任何属性之前,以下代码实际上不会引发异常

using(SPSite site = new Site("http://portal/")) 
{    
    SPWeb web = site.OpenWeb("/newUrl/"); // no exception

    string title = web.Title;  // throws exception
}
当然,可以通过这种方式检查URL的可用性,但这更像是一种黑客行为,而不是好的代码

有人知道怎么解决这个问题吗

再见, 弗洛

正常答案是

if(web.Exists)
但是…你可能想把这个SPWeb包装成一个使用

using(SPWeb web = site.OpenWeb("/newUrl/"))
{
   if(web.Exists)
   {
       string title = web.Title;
   }
}

谢谢,我从来没有想过这么简单的解决办法
using(SPWeb web = site.OpenWeb("/newUrl/"))
{
   if(web.Exists)
   {
       string title = web.Title;
   }
}