title: How to access network shared drives through web application ASP.NET C#?
body: <p>I have searched through web and tried all possible solution but my web app failed every time !
  I have bunch of shared drive paths which I want to access through Web app. I have credentials to access this shared drive paths. 
  The possible solution I found was enable identity impersonate but my web app is failing me in that case. I tried accessing it Using UNC API but that is failing too. I have been told that I can access this shared drives as directory service (dont need to use UNC API).
  Share your thoughts if you have any !
  Thank you! </p>
  
  <p><strong>Enable Identity Impersonate</strong> </p>
  
  <p>In Web.Config</p>
  
  <pre><code>&lt;identity impersonate="true" userName="username" password="pass"&gt;
  </code></pre>
  
  <p>and it is not able to locate my project when I am enabling identity impersonate 
  --Gives System.IO.DirectoryNotFoundException</p>
  
  <p>(tried changing authentication mode(Windows,None,etc) in web.config -- same above error)</p>
  
  <p><strong>UNC Access</strong></p>
  
  <p>I took a copy of UNCAccessWithCredentials from here </p>
  
  <p><a href="https://www.codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials" rel="nofollow noreferrer">https://www.codeproject.com/Articles/43091/Connect-to-a-UNC-Path-with-Credentials</a></p>
  
  <pre><code>using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials()) 
  //access network drives through functional id 
  { 
  
  try
  {
  if (unc.NetUseWithCredentials(sharedrive, functionalID, domainName, 
  functionalPass))
  { 
  string[] files = Directory.GetFiles(sharedrive);
  }
  }
  }
  </code></pre>
  
  <p>It throws error 87 inside NetUseWithCredentials() method</p>