title: C# System.IO.File.Copy from shared drive works on localhost but access to the path is denied on server
body: <p>I want to copy a pdf from a shared folder to a project folder. So I use System.IO.File.Copy:</p>
  
  <pre><code>System.IO.File.Copy(@"\\netstore\IT\SIGN\112454.pdf", "C:\inetpub\wwwroot\myaspmvcwebapisite\temp\112454.pdf", true);
  </code></pre>
  
  <p>The file copies when I run the application locally on my machine but when I publish it to the server and go to the site I get:</p>
  
  <pre><code>signature-service.ts:120 {"$id":"1","Message":"An error has occurred.","ExceptionMessage":"Access to the path '\\\\netstore\\IT\\SIGN\\112454.pdf' is denied.","ExceptionType":"System.UnauthorizedAccessException","StackTrace":"   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)\r\n   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)\r\n   at api.valbruna.local.Controllers.ValShip.SignatureController.Post(Int32 id)"}
  </code></pre>
  
  <p>How do I grant access to the site to access that file location?</p>
  
  <p>Please note:</p>
  
  <ul>
  <li>The site is a MVC Web API INTRANET application</li>
  <li>It uses windows based authentication</li>
  <li>When I say localhost I mean within visual studio(IISExpress)</li>
  </ul>
  
  <p>What I have tried:</p>
  
  <ul>
  <li>Granting EVERYONE access to the folder \\netstore\IT\SIGN\</li>
  </ul>
  
  <p>I have looked at other posts(<a href="https://stackoverflow.com/questions/4877741/access-to-the-path-is-denied">Access to the path is denied</a>) on stack overflow but most of the answers say to grant access to IIS_USRS and I have given everyone access so that doesn't work.</p>
  
  <p>---Update 1---</p>
  
  <p>@Chris Pratt I have updated my IIS settings based on the link you provided.  </p>
  
  <ol>
  <li>The identity field has been updated from NetworkService to ApplicationPoolIdentity.</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/xvAs4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xvAs4.png" alt="enter image description here"></a></p>
  
  <ol start="2">
  <li>I granted full access to the <code>&lt;domainname&gt;\&lt;machinename&gt;$</code></li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/uFOm0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uFOm0.png" alt="enter image description here"></a></p>
  
  <p>---Update 2---</p>
  
  <p>@jp2code I turned on network discovery and I am still getting the same error.</p>
  
  <p><a href="https://i.stack.imgur.com/o9jOi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o9jOi.png" alt="enter image description here"></a></p>
  
  <p>---Update 3---</p>
  
  <p>As a temporary workaround using an <a href="http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User" rel="nofollow noreferrer">Impersonation class</a> works in accessing the shared folder:</p>
  
  <pre><code>using (new Impersonator("username", System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName, "password"))
  {
      // code that executes under the new context.
      sizingDoc.LoadFromFile(sigDocUrl);
  }
  </code></pre>