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();

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.
  • Does the user you're running as have access to the task list, or the site it's in? 'Admin' users on a system may not have access to the site itself.
    – James Love
    Dec 20, 2011 at 9:03
  • 1
    admin account has full control on the list and the normal users have contribute permission. If i assign network credential object to the web request, it works fine (even if the credentials are of a normal user)
    – Shankar
    Dec 20, 2011 at 9:56
  • You may still need to assign DefaultCredentials to the object then (which returns the current user I think).
    – James Love
    Feb 20, 2012 at 11:09
  • Were you able to resolve this issue? We are facing the similar problem. Please let us know how it was resolved. Thanks, Mubin
    – user7429
    Mar 20, 2012 at 0:04
  • @Mubin, sorry i was not able to fix it!
    – Shankar
    Mar 26, 2012 at 6:30

2 Answers 2


I made something similar recently.

Ensure that you pass valid credentials, the url is valid and your user has the "use remote interfaces" permission (you don't need anything more except, obviously at least read access to the targeted list)

    WebRequest request = WebRequest.Create("http://{relevant SPWeb url}/_vti_bin/owssvr.dll?Cmd=Display&List=b82d7210-4730-412d-91f7-54f5ed46c699&XMLDATA=TRUE");
    listService.Credentials = new NetworkCredential("admlbar", "Epsilon$123", "domain");
    WebResponse response = request.GetResponse();
    StreamReader sr = new StreamReader(response.GetResponseStream());
    String responseAsString = sr.ReadToEnd().Trim(); // do whatever you need with the response through Linq2xml, etc.

enter image description here


Try :

XmlDocument  myXMLDocument = new XmlDocument();

  • 1
    Amit, I tried but I got the 401 Unauthorized exception!
    – Shankar
    Dec 20, 2011 at 14:57
  • Are you doing it on some button click? Please ensure that you do it via HTTP-GET request and not POST. Dec 21, 2011 at 5:32
  • As i have mentioned in my post, this is a .exe application as a scheduled task that runs every day in the server.
    – Shankar
    Dec 21, 2011 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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