Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 533071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:28:15+00:00 2026-05-13T09:28:15+00:00

Below are 2 code snippets used to check if a folder exists in a

  • 0

Below are 2 code snippets used to check if a folder exists in a SharePoint document library.
The PROPFIND method seems to work, while the other method, using HEAD results in a 401.

Can someone please tell me why? Don’t get distracted by the credentials, I’ve set it to the same in both examples, and it works fine….

Here is the code that works:

// Create the web request object
var oReq = (HttpWebRequest)WebRequest.Create(url);

// Set the needed properties
oReq.Method = "PROPFIND";
oReq.Credentials = this.wsLists.Credentials; // Use same credentials as wsLists. 
oReq.AllowAutoRedirect = true;
oReq.UserAgent = "Microsoft-WebDAV-MiniRedir/6.1.7600";

// Enumerate through top level only, increasing the depth will find children.
oReq.Headers["Depth"] = "0";
oReq.Headers["translate"] = "f";
var oRequest = new StreamWriter(oReq.GetRequestStream());
oRequest.WriteLine();
oRequest.Close();
var oResponse = new StreamReader(oReq.GetResponse().GetResponseStream());
string sResponse = oResponse.ReadToEnd();
oResponse.Close();

and here is the offending code:

private bool MossResourceExists(string url)
{
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "HEAD";

    // Create a new CredentialCache object and fill it with the network
    // credentials required to access the server.
    var myCredentialCache = new CredentialCache();
    if (!string.IsNullOrEmpty(this.Domain ))
    {
        myCredentialCache.Add(new Uri(url),
       "NTLM",
       new NetworkCredential(this.Username , this.Password , this.Domain )
       );
    }
    else
    {
        myCredentialCache.Add(new Uri(url),
       "NTLM",
       new NetworkCredential(this.Username , this.Password )
       );
    }

    request.Credentials = myCredentialCache;

    try
    {
        request.GetResponse();
        return true;
    }
    catch (WebException ex)
    {
        var errorResponse = ex.Response as HttpWebResponse;

        if (errorResponse != null)
            if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                return false;
            else
                throw new Exception("Error checking if URL exists:" + url + ";Status Code:" + errorResponse.StatusCode + ";Error Message:" + ex.Message ) ;
    }
    return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:28:15+00:00Added an answer on May 13, 2026 at 9:28 am

    My two cents:

    I think it has to do with the way WebDAV works:

    • the first request is always sent anonymous, because WebDAV is a “challenge / response” protocol, That first request without auth headers is necessary; the response from WebDAV contains a nonce to validate the next request, helping deflect against, for example, replay attacks. (from answer to this question, see links in answer for more info).

    • Is the site you are trying to access in your “Local Intranet” zone in IE? If not, the following might give some more info on your issue and a possible woraround:

    Understanding Why it Happens

    When you use Internet Explorer to
    access the WebDAV site, Internet
    Explorer uses Windows HTTP Services
    (WinHTTP). WinHTTP sends user
    credentials only in response to
    requests that occur on a local
    intranet site during an authenticated
    logon process. However, WinHTTP does
    not check the security zone settings
    in Internet Explorer to determine
    whether a Web site is a local intranet
    site. Instead, WinHTTP depends on the
    proxy settings in Internet Explorer to
    determine whether a Web site is a
    local intranet site.

    If the Automatically detect settings
    option is not enabled, any
    auto-configuration script that is
    defined will not be processed. WinHTTP
    will not identify the WebDAV site as a
    local intranet site. Therefore,
    WinHTTP will send out a request
    without user credentials, and you will
    be prompted to type user credentials.

    So as you can see, this problem only
    seem to appear on an Extranet site and
    not on an Intranet site. Unfortunately
    many of my customers run geophysical
    solutions all over the country with no
    proxy’s in between.
    From here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 349k
  • Answers 349k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found that the best solution is to use a… May 14, 2026 at 6:44 am
  • Editorial Team
    Editorial Team added an answer As M.A Hanin pointed out in his comment, it looks… May 14, 2026 at 6:44 am
  • Editorial Team
    Editorial Team added an answer Since you are working within Windows, you probably won't be… May 14, 2026 at 6:44 am

Related Questions

SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
I'm a C# developer who is working through Real World Haskell in order to
I don't like to lock up my code with synchronized(this) , so I'm experimenting
I'm new to NHibernate and am attempting to use it to connect to DB2.
Problem solved, see below Question I'm working in Flex Builder 3 and I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.