Creating WebReuest with Credentials for SharePoint

using System.Net;
using System.IO;

WebRequest mywebReq;
WebResponse mywebResp;
StreamReader sr;
string strPageHtmlContent;
mywebReq = WebRequest.Create("http://yoursharepointsite");
mywebReq.PreAuthenticate = true;

/************** Use this*************************/
NetworkCredential networkCredential = new NetworkCredential("yourUserName", "yourPassword");
mywebReq.Credentials = networkCredential;

/**************Or use this*************************
mywebReq.Credentials = CredentialCache.DefaultCredentials;

mywebResp = mywebReq.GetResponse();
sr = new StreamReader(mywebResp.GetResponseStream());
strPageHtmlContent = sr.ReadToEnd();
lbl8.Text = strPageHtmlContent;

This entry was posted in SharePoint 2010, Visual Studio 2010. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s