File Download (being used by another process)

0
0

I am using the following line of vb code to download a remote file from a server (the same server as the application is running on)

Application.Download(File.OpenRead(FileNameandLoc), ShortName)

Where FileNameandLoc is the full file name and ShortName is the display name

This works brilliantly well, however if I try to latterly delete the file using File.Delete(filename) I get the error

System.IO.IOException: ‘The process cannot access the file ‘filename’ because it is being used by another process.’

The issue appears to be that after using file.openread I need to then close the file but I cannot see a means of doing this within the syntax

 

Thanks for your help

 

 

  • You must to post comments
0
0

Hi Andrew,

Try this:

using (FileStream fs = File.OpenRead(Path))
   {
      using (BinaryReader br = new BinaryReader(fs))
      {
         Application.Download(br.BaseStream, "FileName");
      }
   }
It’s important that the file is closed from reading after use and the best way to do that is something like above.
Let me know if this works for you!
Best regards,
Levie
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.