Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I was wondering how people have gone about programatically checking if SharePoint is still available?

I use the following now to check it, but it relies on the SharePoint object model and must run on the machine in question... is there an approach for doing this remotely? Simply pinging the server is not an option as this won't pick up on instances when IIS has stopped working:

public class Uptime
    {
        /// <summary>
        /// Checks uptime directly by using the SharePoint Object Model
        /// </summary>
        /// <param name="siteCollection">The site collection to check availability for</param>
        /// <returns>True on a connection, false if no connection was able to be made</returns>
        public bool CheckUptimeDirect(string siteCollection)
        {
            try
            {
                using (var site = new SPSite(siteCollection))
                {
                    using (var web = site.OpenWeb())
                    {
                        web.Dispose();
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
share|improve this question
    
why don't you just try to make a simple "HttpWebRequest" to you site collection and check the response status returned? –  Furqan Sep 6 '12 at 7:40
    
Oh! I don't know how (new to development) - could you provide an example? –  ElvisLikeBear Sep 6 '12 at 9:36
add comment

1 Answer

up vote 3 down vote accepted

you can try the following ,

       string siteColl = @"http://server:port/" ;
       HttpWebRequest hwr = HttpWebRequest.Create(siteColl) as HttpWebRequest;
        //hwr.Credentials = new System.Net.NetworkCredential("user","pass","domain") ;
        HttpWebResponse resp =  hwr.GetResponse() as HttpWebResponse;
        if (resp.StatusCode == HttpStatusCode.OK)
        {
            Response.Write("site is up and running.");
        }

if the site has anonymous access enabled and is up and running, you shall know of it. You can also pass network credentials if it allows authenticated users only. And this should work remotely as well, without any sharepoint API.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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