Tuesday, December 3, 2013

Check if SharePoint Site already exists

public bool SiteExists(string url)
        {
            bool Exists = false;
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                       {
                           using (SPSite site = new SPSite(url))
                           {

                               using (SPWeb web = site.OpenWeb(url, true))
                               {
                                   Exists= true;
                               }

                           }
                       });

            }
            catch (FileNotFoundException)
            {
                Exists= false;
            }
            return Exists;
        }

No comments:

Post a Comment