title: Moving files on the server side using webservice
body: <p>I am working on a requirement that has the following logic. code is in C# and .NET CF 3.5</p>
  
  <ol>
  <li><p>Upload some files from a mobile device to a web server.</p></li>
  <li><p>when the upload is successful, the file is moved to an archived folder on the mobile device.</p></li>
  <li><p>Download some files from the server to the mobile device.</p></li>
  <li><p>When the download is successful, the file has to be moved to an archived folder on the server side in order so as not to download the same file again.</p></li>
  </ol>
  
  <p>Wrote a web service (asmx) to handle this operation. The uploading and downloading works fine.</p>
  
  <p>The webservice uses the function FileInfo.MoveTo() to move the file from the downloaded folder to the archives on the web server.</p>
  
  <p>This works locally fine (when the webservice and the client calling the webservice are hosted on the same machine) but when deployed to a server, I get this message "the process cannot access the file because it is being used by another process".</p>
  
  <p>I have given the necessary permissions to the IIS account on the server side. I would like to know if that can be achieved at all from the mobile device or is there any other way to invoke that call on the mobile device. I need to execute this method immediately after the file is downloaded.</p>
  
  <p>Sample code is attached.</p>
  
  <pre><code>fileEntriesD = SomeWebService.FilesList();
  
          string[] extractedFiles = fileEntriesD.Split(',');
  
          foreach (string fileName in extractedFiles)
          {
              //dothe file downloading
              //code comes here.......   
          }
  
          //move the file on the server once all the files are downloaded
  
          foreach (string DumpfileName in extractedFiles)
          {
            //after the download is complete move the file to the archived folder
            string MoveFileOnServerStatus;
            MoveFileOnServerStatus = SomeWebService.MoveFileToArchive(DumpfileName);
            MessageBox.Show(MoveFileOnServerStatus);
          }
  </code></pre>
  
  <p>code for the WebMethod for MoveFileToArchive(DumpfileName)</p>
  
  <pre><code>   [WebMethod(Description="move the file to the archive location")]
     public string MoveFileToArchive(string fileArchiveName)
     {
          try
          {
              string SerPathD = GetLocationOfFiles + "\\" + "ArchivedDispatchedFiles";
  
              FileInfo MFTA = new FileInfo(SerPathD + "\\" + fileArchiveName);
  
              MFTA.MoveTo(SerPathD + "\\" + fileArchiveName);
          }
          catch(IOException ex)
          {
              //if there is any error then return the error message.
                 return ex.Message.ToString();
          }
  
              //if the moving was successful then return 1 to the client.
              return "1";
     }
  </code></pre>