tags:

views:

33

answers:

1

I have been using this code to read in a file from a document repository in sharepoint:

WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create("http://servername/realestate/SiteAssets/navigation.txt");
objRequest.Timeout = 10000;
objRequest.UseDefaultCredentials = true;
objRequest.Proxy.Credentials = objRequest.Credentials;

objResponse = (WebResponse)objRequest.GetResponse();

using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
    navBar = sr.ReadToEnd();
    sr.Close();
}

I just migrated to a new environment, and I am getting a 401 unauthorized error with this code - but, instead of using servername, I am now using hostname (since the new environment has a domain assigned to it). How can I navigate this issue, even though I am now using a host in my HttpWebRequest object? And, if this should not be causing the issue, I would like to hear recommendations as well. Thanks.