문제

URL이 있고 주어진 URL에 대한 하위 사이트로 존재하는지 확인하고 싶습니다.

  • i URL= www.go.com
  • = www.go.com의 ul= www.go.com/abx 또는 not
  • 가 있는지 확인하고 싶습니다.

나는 +1000 하위 웹을 가지고 있고, 나는 그들을 모두 반복해야합니까, 바로 가기 없음

도움이 되었습니까?

해결책

SuperMode와 Unie가 제안한 것과 함께 할 수 있습니다. 아래 코드를 사용하도록 선택할 수도 있습니다.

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 내에 있는지 확인하십시오. 웹의 사이트 상대 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