I am creating a task scheduler for Windows Server 2008 to send mails for events whose date has passed and I am trying to access the task list using owssvr.dll with the following code in sharepoint 2010 to get the event date. I am unable to execute this task even if it is set to run with admin privileges.
I get the 401 unauthorized exception.
string reqUrl = url + @"/_vti_bin/owssvr.dll?Cmd=Display&List=" + ListId + "View=" + ViewId + "&XMLDATA=TRUE&noredirect=true&Query=*&FilterField1=Event_x0020_Date&FilterValue1=" + String.Format("{0:u}", DateTime.Today);
HttpWebRequest httpwebRequest = (HttpWebRequest)HttpWebRequest.Create(reqUrl);
HttpWebResponse httpwebResponse = (HttpWebResponse)httpwebRequest.GetResponse();
XmlDocument doc = new XmlDocument();
//Store Response to Stream
Stream streamResponse = httpwebResponse.GetResponseStream();
StreamReader streamResponseReader = new StreamReader(streamResponse);
//Store ResponseStram As String.
string strResponseBody = streamResponseReader.ReadToEnd();
doc.LoadXml(strResponseBody);
I tried setting System.Net.CredentialCache.DefaultNetworkCredential and it worked in my development server. But when i changed the url property and deployed it in stage environment it gave me a 404 error. I am able to access this url in browser without any issue.
System.Net.WebException: The remote server returned an error: (404) Not Found.

