-4

I have a page to upload file .txt by using PLUpload library (PLUpload). It worked when I test in client computer for all of browser : IE, Chrome, FF... But when I test in Window Server where hosting this website it throw error:

The process cannot access the file 'SystemPath\Test.txt' because it is being used by another process.

The website write by ASP.NET and I think root cause is about the security of Window Server. The error code is Error #-200: HTTP Error.

Here is the code when upload :

            using System.IO;
            MemoryStream uploadStream = new MemoryStream();                
            using (FileStream source = File.Open(tempFile, FileMode.Open))
            {
                source.CopyTo(uploadStream);
            }

Question: Why IE throw that error just only Window Server and how to fix that ?

Rai Vu
  • 1,595
  • 1
  • 20
  • 30
  • 3
    That code doesn't upload anything and it looks like server side code. We might need actual code for uploading and how you handle that server side. It's especially useful to know where you're planning to save uploaded file. – Adriano Repetti Dec 19 '16 at 09:54
  • You should close your stream after first upload. Also while uploading a file to server, if app is running under IIS, you should set upload folder as chmod 777 (full-write) and define root path for your file path. It's named as fully qualified file path. ps: Do not forget seeking to the beginning of stream before writing it to file. Otherwise content will be empty. – Kadir Lüzumlar Dec 23 '16 at 10:46

1 Answers1

2

There are a variety of processes that could lock up the file.

Eric Lippert suggested that it could be the antivirus: C# file is being used by another process

João Sousa recommends checking your code to make sure it disposes of all connections to the file when it is done: Process cannot access the file because it is being used by another process

Because the error is coming from the file system, anything that interacts with the file system could be locking the file. These may not be the cause of your error, but they are good places to start looking.

Community
  • 1
  • 1
Jesse Potter
  • 827
  • 5
  • 20