Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - The process cannot access the file

Reply
 
Old 05-15-2009   #1 (permalink)
spunkopolis


 
 

The process cannot access the file

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


My System SpecsSystem Spec
Old 05-18-2009   #2 (permalink)
Andrew Morton


 
 

Re: The process cannot access the file

spunkopolis wrote:
Quote:

> 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?
Quote:

> 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.
Quote:

> ... do some work
>
> sw.Flush()
Not needed, because .Close() flushes the stream.
Quote:

> sw.Close()
> sr.Close()
>
> File.Delete(FullPathName)
> File.Move(NewFullPathName, FullPathName)
> End If
HTH

Andrew


My System SpecsSystem Spec
Old 05-18-2009   #3 (permalink)
Anthony Lopez


 
 

Re: The process cannot access the file

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?


On 5/18/09 3:13 AM, in article 77cqm4F1guio5U1@xxxxxx, "Andrew
Morton" <akm@xxxxxx-press.co.uk.invalid> wrote:
Quote:

> spunkopolis wrote:
Quote:

>> 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?
>
Quote:
Quote:

>> 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.
>
Quote:

>> ... do some work
>>
>> sw.Flush()
>
> Not needed, because .Close() flushes the stream.
>
Quote:

>> sw.Close()
>> sr.Close()
>>
>> File.Delete(FullPathName)
>> File.Move(NewFullPathName, FullPathName)
>> End If
>
> HTH
>
> Andrew
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Elevated process can't write to %temp% - access denied ? Vista General
Elevated process can't write to %temp% - access denied ? Vista security
open a file, wait for user to amend file, close & process PowerShell
Failover Guest Cluster -- 'The process cannot access the file becauseit is being used by another process.' Virtual Server
Re: The Process cannot access the file ... PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46