title: Copy a file from local drive to shared drive using C#
body: <p>I want to copy a file from my local drive to a shared network path. </p>
  
  <p>I have tried the following way:</p>
  
  <pre><code>string remoteUserName = 
            WebConfigurationManager.AppSettings["remoteUsername"].ToString();
  string remotePassword =
            WebConfigurationManager.AppSettings["remotePassword"].ToString();
  string remoteDomain = 
            WebConfigurationManager.AppSettings["remoteDomain"].ToString();
  string remoteFilePath = 
            WebConfigurationManager.AppSettings["remoteFilePath"].ToString();
  
  using (var impersonation = new 
            ImpersonatedUser(remoteUserName, remoteDomain, remotePassword))
  {
      CreateErrorLog("Logged in successfully - User and password are correct.", 
                     "Action" + " - " + "controllerName");
      string filePath = remoteFilePath;
      string fileName = "txt.txt";
      StreamWriter SW1;
      FileIOPermission myPerm = new 
                 FileIOPermission(FileIOPermissionAccess.AllAccess, filePath + fileName);
      myPerm.Assert();
      SW1 = System.IO.File.CreateText(filePath + fileName);
  }
  </code></pre>