Process used by another

G

Guest

Hi,

i have a Web application and i get this error:

The process cannot access the file
"c:\inetpub\wwwroot\dotnet\Soluciones\Calculations\PhoneTariffs\Errors\Log.txt" because it is being used by another

The code that generates this error is the following:

Directory.CreateDirectory("c:\inetpub\wwwroot\Error");
File.Create("c:\inetpub\wwwroot\Error\log.txt");

System.IO.StreamWriter StreamLog=new
System.IO.StreamWriter("c:\inetpub\wwwroot\Error\log.txt");
StreamLog.Write(e.Message);
StreamLog.Close();

How could avoid that error?.
 
W

Willy Denoyette [MVP]

Josema said:
Hi,

i have a Web application and i get this error:

The process cannot access the file
"c:\inetpub\wwwroot\dotnet\Soluciones\Calculations\PhoneTariffs\Errors\Log.txt"
because it is being used by another

The code that generates this error is the following:

Directory.CreateDirectory("c:\inetpub\wwwroot\Error");
File.Create("c:\inetpub\wwwroot\Error\log.txt");

System.IO.StreamWriter StreamLog=new
System.IO.StreamWriter("c:\inetpub\wwwroot\Error\log.txt");
StreamLog.Write(e.Message);
StreamLog.Close();

How could avoid that error?.

You open the same file two times here.
There is no need for - File.Create("c:\inetpub\wwwroot\Error\log.txt");

Willy.
 
S

Steve Walker

You open the same file two times here.
There is no need for - File.Create("c:\inetpub\wwwroot\Error\log.txt");

And the StreamWriter created by that line of code is still open, which
is probably what is locking the file.
 
W

Willy Denoyette [MVP]

Steve Walker said:
And the StreamWriter created by that line of code is still open, which is
probably what is locking the file.

Exactly!

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top