The process cannot access the file

S

spunkopolis

I have an application that is working on WindowsXP and Windows2000. I
recently moved it onto a new Windows2003 Server Service Pack 2 machine. It is
now getting an error message which reads "The process cannot access the file
<filename> because it is being used by another process"

this is what I have (abreviated version):

If File.Exist(FullPathName) Then
Dim sr As StreamReader = File.OpenText(FullPathName)
Dim sw As StreamWriter = File.CreateText(NewFullPathName)

... do some work

sw.Flush()
sw.Close()
sr.Close()

File.Delete(FullPathName)
File.Move(NewFullPathName, FullPathName)
End If
 
A

Andrew Morton

spunkopolis said:
I have an application that is working on WindowsXP and Windows2000. I
recently moved it onto a new Windows2003 Server Service Pack 2
machine. It is now getting an error message which reads "The process
cannot access the file <filename> because it is being used by another
process"

Would the be the input or output file? Did your program crash at some time
so that its previous invocation has left a lock on one of the files?
this is what I have (abreviated version):

If File.Exist(FullPathName) Then
Dim sr As StreamReader = File.OpenText(FullPathName)
Dim sw As StreamWriter = File.CreateText(NewFullPathName)

You can use a New FileStream to get more options as to how to open the file,
e.g. with FileShare.Read.
... do some work

sw.Flush()

Not needed, because .Close() flushes the stream.
sw.Close()
sr.Close()

File.Delete(FullPathName)
File.Move(NewFullPathName, FullPathName)
End If

HTH

Andrew
 
A

Andrew Morton

spunkopolis said:
I have an application that is working on WindowsXP and Windows2000. I
recently moved it onto a new Windows2003 Server Service Pack 2
machine. It is now getting an error message which reads "The process
cannot access the file <filename> because it is being used by another
process"

Would the be the input or output file? Did your program crash at some time
so that its previous invocation has left a lock on one of the files?
this is what I have (abreviated version):

If File.Exist(FullPathName) Then
Dim sr As StreamReader = File.OpenText(FullPathName)
Dim sw As StreamWriter = File.CreateText(NewFullPathName)

You can use a New FileStream to get more options as to how to open the file,
e.g. with FileShare.Read.
... do some work

sw.Flush()

Not needed, because .Close() flushes the stream.
sw.Close()
sr.Close()

File.Delete(FullPathName)
File.Move(NewFullPathName, FullPathName)
End If

HTH

Andrew
 
A

Anthony Lopez

It is the Input File, never makes it to output file. Since the output file
does not exist and is being created, would it be possible for this error to
be raised? The program did not crash nor does it attempt to open the file
before this point.

DID I MENTION THAT THIS IS WORKING ON XP AND 2000 SERVER PLATFORMS?
 
A

Anthony Lopez

It is the Input File, never makes it to output file. Since the output file
does not exist and is being created, would it be possible for this error to
be raised? The program did not crash nor does it attempt to open the file
before this point.

DID I MENTION THAT THIS IS WORKING ON XP AND 2000 SERVER PLATFORMS?
 

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