Shiva Saurabh
Shiva Saurabh

Reputation: 1289

"The process cannot access the file because it is being used by another process" but only in IIS

When i execute a my code in my local system it is working fine, but when put in IIS its showing the error "The process cannot access the file abc.pdf because it is being used by another process". putting my code below

using (FileStream fs = File.Create(AppConfig.DNotePath + fileName))
{
        fs.Write(content, 0, (int)content.Length);
        fs.Close();
}

showing error near using only in IIS

Upvotes: 0

Views: 6776

Answers (2)

Shiva Saurabh
Shiva Saurabh

Reputation: 1289

The problem arised by using the date time for filename. you can use some unique names other than Datetime because the IIS executes faster in terms of milliseconds and takes repititive name when date time is used. GUID is preferable.

Upvotes: 1

Jermay
Jermay

Reputation: 97

Did you check from the server's task manager for a process running in the background which might be using the file abc.pdf?

I had the same issue when I was reading excel files in my application and the application sometimes ran on background after closing and locked resources.

Upvotes: 0

Related Questions