title: How to create a folder on a server by passing credentials using c#
body: <p>I am working on a ASP.NET application using C# that is trying to read some files from a website by logging in and then writing the files on local drive.</p>
  
  <p>I have already passed network credentials to logon to the website by reading the default credentials using - </p>
  
  <pre><code>request.Proxy.Credentials = CredentialCache.DefaultCredentials;
  </code></pre>
  
  <p>Now i want to store the files on a server directory that requires some credentials to access the location.</p>
  
  <p>Code of logging on to the website - </p>
  
  <pre><code>                string webUrl = "https://web.site.com/";
  
              string formParams = string.Format("user={0}&amp;password={1}", username, password);
  
              WebRequest req = WebRequest.Create(webUrl);
              req.ContentType = "application/x-www-form-urlencoded";
              req.Method = "POST";
              req.Proxy.Credentials = CredentialCache.DefaultCredentials;
              byte[] bytes = Encoding.ASCII.GetBytes(formParams);
              req.ContentLength = bytes.Length;
              using (Stream os = req.GetRequestStream())
              {
                  os.Write(bytes, 0, bytes.Length);
              }
              WebResponse resp = req.GetResponse();
  
              cookieHeader = resp.Headers["Set-cookie"];
  </code></pre>
  
  <p>And the location is <code>\\11.11.11.11\Folder\</code></p>
  
  <p>How can I pass credentials for accessing that location?
  I have learned about <code>impersonation</code> but not getting anything helpful so far. I have credentials that gives access to the location. But how can I do so by using C# code?</p>
  
  <p>Thanks in advance :)</p>