0

Is there anyone who can maybe explain the error I am getting on this? The error I receive

The process cannot access the file 'C:\Users\Roelf\Documents\test555.wav' because it is being used by another process.

Everything is closed. I even restarted everything. Downloading works like a charm though. I used this post as a reference. Any help is greatly appreciated (Note: I know the error is telling me that the file is being used by something else. The problem is I can't figure out what as VS is the only programme currently using it.)

public void UploadAudioFile(string filename)
{
    string path0 = Path.Combine("ftp://vps573557.ovh.net/TranscriptionData/AudioFiles/", filename);
    string path1 = Path.Combine(@"C://Users/Roelf/Documents/Transcriptions/", filename);
    WebClient client = new WebClient();
    client.Credentials = new NetworkCredential("user", "pass");

    client.UploadFile(path0, path1);
}
Lauren Rutledge
  • 1,195
  • 5
  • 18
  • 27
  • Use the [Unlocker](http://www.emptyloop.com/unlocker/) tool to determine which process is using the file. If you found out it's not used by any process, put a breakpoint at the `client.UploadFile(..)` line, run until you reach this line and then check again with Unlocker. You might have some code that locks the file before entering the `UploadAudioFile` because I can't see anything wrong with it. – 41686d6564 stands w. Palestine Aug 30 '18 at 14:17
  • Sorry I only saw your post now. But thank you. Went to my old code and did what you said and it also helped. Now I am stuck with the decision of which system to use :D – Roelf Mitton Aug 30 '18 at 20:06

1 Answers1

0

Try to use:

 using(FileStream stream = new FileStream(fullFileName, FileMode.Create))
 {
     // do something here with your stream
 }

This could avoid those types of problems.

Lauren Rutledge
  • 1,195
  • 5
  • 18
  • 27
CREM
  • 1,929
  • 1
  • 25
  • 35