質問

URLを持ち、特定のURLのサブサイトとして存在するかどうかを確認したいです。

  • URL= www.go.com
  • = www.go.comがurl= www.go.com/abxを持っているかどうかをチェックしたいか、

私は+ 1000冊のサブウェブを持っています、私はそれらすべてをループしなければならない、ショートカットはありませんか?

役に立ちましたか?

解決

あなたはスーパーモードとニュージーが提案されたもので行くことができます、あなたはまた以下のコードを使うことを選ぶかもしれません:

using (SPSite site = new SPSite("http://www.go.com/"))    
{    
        using (SPWeb oWeb= site.OpenWeb())
        {
            SPWeb IsWebExists = oWeb.Webs.FirstOrDefault(x => x.Name == "abx");
            if (IsWebExists == null)
            {
                  //Your Code
            }
        }
}
.

他のヒント

下のコード:

using (SPSite site = new SPSite("http://www.go.com/"))
{
  using (SPWeb web = site.OpenWeb("abx"))
  {
     if (web.Exists)
         Console.WriteLine("exists");
     else
         Console.WriteLine("not exists");

  }
}
.

site.OpenWebの内部では、Webのサイト相対URLを提供します。

次の

を試すことができます
string serverUrl = "http://myserver";
string siteUrl = "/sites/SiteCollection";
string subSiteUrl = "This Subsite Does Not Exist";
using (SPSite site = new SPSite(serverUrl + siteUrl))
{
    using (SPWeb web = site.OpenWeb(subSiteUrl))
    {
        if (web.Exists)
        {
            // do work with the web...
            Console.WriteLine(site.Url);
            Console.WriteLine(web.Url);
        }
    }
}
.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top