The process cannot access the file

  • Thread starter Thread starter spunkopolis
  • Start date Start date
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
 
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
 
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
 
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?
 
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?
 
Back
Top