1

I am trying to login programatically to a sharepoint app and get the html code of specific page within that website. Is there a way how I can do that programatically? I am having problems with the part where I need to pass the login parameters and access the url I need to get the html code. Thanks in advance everyone, Laziale

 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://mysite.sharepoint.com");
        NetworkCredential credentials = new NetworkCredential("myUser", "myPass");
        request.Credentials = credentials;

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream receiveStream = response.GetResponseStream ();

        StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
        string html = readStream.ReadToEnd();

        response.Close();
        readStream.Close();
Laziale
  • 7,965
  • 46
  • 146
  • 262
  • This question should be moved to [sharepoint.stackexchange.com](http://sharepoint.stackexchange.com/) – pstrjds Jul 29 '11 at 13:22
  • 2
    @pstrjds - This seems like more of a general programming question (despite the reference to sharepoint), I would suggest leaving it here. – Peter Jul 29 '11 at 13:35
  • @Patricker - now that I have had my coffee I agree :) – pstrjds Jul 29 '11 at 14:01

1 Answers1

1

Have you tried something like:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("url goes here");
request.Credentials = new NetworkCredential("username", "password");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream ();

StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
string html = readStream.ReadToEnd();

response.Close();
readStream.Close();
Peter
  • 9,643
  • 6
  • 61
  • 108
  • I am getting 'the handle is invalid' on the 2nd line, the place where I submit the credentials – Laziale Jul 29 '11 at 14:00
  • code posted, check the top of the page. Thanks for helping out – Laziale Jul 29 '11 at 14:20
  • @Laziale - It seems your error is probably caused by system configuration, see http://stackoverflow.com/questions/5950404/networkcredential-error-in-asp-net – Peter Jul 29 '11 at 14:25