Pergunta

Eu tenho um URL e quero verificar se ele existe como subsite para um determinado URL.

  • Eu tenho uma URL = www.go.com
  • Quero verificar se = www.go.com tem URL = www.go.com/abx ou não

Tenho +1000 sub-redes, preciso fazer um loop em todas elas, sem atalho?

Foi útil?

Solução

Você pode seguir o que Supermode e Unnie sugeriram, você também pode optar por usar o código abaixo:

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

Outras dicas

Experimente o código abaixo:

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");

  }
}

Apenas certifique-se de dentro site.OpenWeb, você fornece o URL relativo do site da web

Você pode tentar o seguinte

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);
        }
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top