csharp Hong Kong SAR
  • 12 years ago

    HI ! My company bought a software for stroring and accessing document and the software allows us to access document using webdav. That webdav run in Apache server . I tried to use C# to access the document from webdav but it keep throwing unauthorized 401 error. I can access that webdav url in IE or in My Network Place and It works fine. Can anybody tell me how to authenticate to webdav url? Can anybody help me and show me how to access a webdav url folder ? I want to get all the folder list and the files also. This is the code that I wrote to access the webdav URL

    string strRootURI = http://URL/webdav;

    string strUserName = "USERID";

    string strPassword = "PASSWORD";

    string strDomain = "DOMAIN";

    string strQuery = ""; byte[] bytes = null;

    System.Net.CredentialCache MyCredentialCache = new System.Net.CredentialCache();

    MyCredentialCache.Add(new System.Uri(strRootURI), "Basic",//"NTLM","Negotiate" //I TRIED THREE DIFFERENT AUTH TYPE DOESN'T WORK ALSO new System.Net.NetworkCredential(strUserName, strPassword, strDomain) );

    // Create the HttpWebRequest object.

    System.Net.HttpWebRequest Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);

    // Add the network credentials to the request.

     Request.Credentials = MyCredentialCache;

    System.Net.WebResponse Response = (HttpWebResponse)Request.GetResponse(); //==> THROW AN 401 UNAUTHORIZED ERROR response.Close();

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Every language has an optimization operator. In C++ that operator is ‘//’”