using (FileStream fs = File.OpenRead(Path)) { using (BinaryReader br = new BinaryReader(fs)) { Application.Download(br.BaseStream, "FileName"); } }
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
Hi Andrew,
Try this:
using (FileStream fs = File.OpenRead(Path)) { using (BinaryReader br = new BinaryReader(fs)) { Application.Download(br.BaseStream, "FileName"); } }
Please login first to submit.