【问题标题】:Sharepoint: How to find out whether an realtive URL is available or already used by a siteSharepoint:如何确定相对 URL 是否可用或已被站点使用
【发布时间】:2023-04-05 06:17:02
【问题描述】:

我如何才能确定某个 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 的可用性,但它更像是一种 hack,而不是好的代码。

那么有人知道如何解决这个问题吗?

再见, 弗洛尔

【问题讨论】:

    标签: sharepoint url moss


    【解决方案1】:

    正常的答案是

    if(web.Exists)
    

    但是...您可能希望将此 SPWeb 包装到 using 中。

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

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 谢谢,我从没想过这么简单的解决方案。 ;)
      猜你喜欢
      • 1970-01-01
      • 2017-09-13
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      • 1970-01-01
      相关资源
      最近更新 更多