Print Page | Close Window

File being used by another process

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=5918
Printed Date: 29 March 2026 at 6:49pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: File being used by another process
Posted By: Mart
Subject: File being used by another process
Date Posted: 23 September 2003 at 12:38pm

This is the error i get:

Server Error in '/' Application.

The process cannot access the file "c:\inetpub\wwwroot\counters\97658826122447124540.txt" because it is being used by another process.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.IOException: The process cannot access the file "c:\inetpub\wwwroot\counters\97658826122447124540.txt" because it is being used by another process.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

[IOException: The process cannot access the file "c:\inetpub\wwwroot\counters\97658826122447124540.txt" because it is being used by another process.]
   System.IO.__Error.WinIOError(Int32 errorCode, String str) +614
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) +888
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) +44
   System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) +79
   System.IO.StreamReader..ctor(String path) +101
   System.IO.File.OpenText(String path) +30
   ASP.jscounter_aspx.page_load() +103
    System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Ob ject sender, EventArgs e) +10
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

it is only temporay, it only happpens after the txt file has been made by using file.create() is there anything i can do to stop this error?

Thanks Mart.




Replies:
Posted By: Mart
Date Posted: 23 September 2003 at 12:48pm

I am also getting this error:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 13: 	
Line 14:                dim sr as StreamReader = File.OpenText(server.mappath("counters\" & request.QueryString("SID") & ".txt"))
Line 15:                value = cint(sr.ReadLine().ToString())
Line 16:                sr.Close
Line 17: 			   

Source File: c:\inetpub\wwwroot\jscounter.aspx    Line: 15

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   ASP.jscounter_aspx.page_load() in c:\inetpub\wwwroot\jscounter.aspx:15
    System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Ob ject sender, EventArgs e) +10
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731


Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

Thanks, Mart.



Posted By: Diep-Vriezer
Date Posted: 23 September 2003 at 2:07pm

First, try

If Dir(server.mappath("counters/" & request.QueryString("SID") & ".txt")) = Request.QueryString("SID") & ".txt" Then

  Dim sReader As StreamReader = File.OpenText(server.mappath("counters/" & request.QueryString("SID") & ".txt"))

  Dim sValue As String = sReader.ReadLine()

  sReader.Close()

  Return True

Else

  Return False

End If

Now, this is in VB.NET, so no C#. If you really want C#, try and make this in C#, because it works in VB.NET like this.

BTW I colored it myself



-------------
Gone..


Posted By: Mart
Date Posted: 24 September 2003 at 12:41am
Thanks for that it works, but what was wrong with my code?


Posted By: Diep-Vriezer
Date Posted: 24 September 2003 at 4:45am
Don't know, I've got some weird error's to that never occor, except when you need the script, so I rebuild the thing, and it might be something else, I don't really know. Maybe it is C#?

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 24 September 2003 at 4:46am
He, did you close the writer?

-------------
Gone..


Posted By: Mart
Date Posted: 24 September 2003 at 9:10am

Im not using C#! And i did close the writer.

mart.



Posted By: Diep-Vriezer
Date Posted: 24 September 2003 at 9:44am
 Wh00ps, just a weird example from Microsoft how your pages SHOULD look like ... Well, why your code didn't work.. Maybe you had the textfile open in a reader or another proces (lol)? But anyway, if it works now, let's not worry to much.

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 24 September 2003 at 9:57am

Maybe it is the cint command.



-------------
Gone..


Posted By: Erik5150
Date Posted: 05 December 2003 at 12:18pm

Im getting this error too

what I'm trying to do is:

Copy an archive from a source path to a dest. path
FileInfo FS = new FileInfo(source);
FS.CopyTo(dest,
true);

then, I got this error message when Im trying to Delete the Original File (the one in the source path).

File.Delete(source);

What I Did was to make a function that waits for exclusive access to the original file doing this:

private
void WaitForExclusiveAccess(string FullPath)
{while
(true){
try
{
FileStream fs = new FileStream(FullPath, FileMode.Open, FileAccess.Read,
FileShare.None);
fs.Close();
break;
}
catch
{Thread.Sleep(4);}

}

so the final code goes like this:

FileInfo FS = new FileInfo(source);
FS.CopyTo(dest,
true);
WaitForExclusiveAccess(source);
File.Delete(source);


but Im afraid this solution isnt just the best one because that Thread.Sleep(4); affects the Page performance.

any suggestions ?



Posted By: MorningZ
Date Posted: 05 December 2003 at 12:34pm

while i dont have the time to pick apart your code with a fine toothed comb right now, i can tell you what the fix is..

you don't have closure on some things.... when you create a file, make sure you close that process before doing something else.. etc



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 07 December 2003 at 7:38am
Yup, that's it. You can't delete or edit a file while a stream is still reading or writing it, or the connection is just open.

-------------
Gone..



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net