0

.NET web application is hosted on machine A were no SharePoint bits are installed. SharePoint is installed in machine B. I can access the SharePoint sites hosted on machine B from machine A through browser.

Is there a way that I can write some code to the web application on A that quires machine B, and checks if a site collection exists (I am allowed to pass the complete URL of the site on machine B to the web application on A).

Any ideas\references\examples will help.

Thanks

1 Answer 1

2

You can use the WebClient class to check if the specified URL exists. Example:

using(var client = new WebClient()) {       
    try{
        string check = client.DownloadString("http://siteroot/subsite");
    }
    catch(Exception ex){    
       //if you get here the site doesn't exist
    }
}

Or you can use following code to check if site exists with X title, for using this you will need to add reference to SharePoint Client dll's in your web project:

using (ClientContext context = new ClientContext(spUri))
{
   context.Credentials = CredentialCache.DefaultNetworkCredentials;
   Web web = context.Web;
   context.Load(web, w => w.Title, w => w.Webs);
   context.ExecuteQuery();

    var subWeb = (from w in web.Webs where w.Title == "Website Title" select w).SingleOrDefault();
    if (subWeb != null)
    {
      // if found true
      return true;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.