Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > The process cannot access the file "" because it is being used by another process.

Reply
Thread Tools

The process cannot access the file "" because it is being used by another process.

 
 
RSH
Guest
Posts: n/a
 
      05-19-2006
Hi,

I have an ASP .Net web page that creates a temp directory on the server then
it is using the File.Copy command to move a file to a temp download
directory, Then I am doing a response.Redirect to that URL.

The problem is that whenever I run the page the script fails on the
File.Copy() command everytime with an error of:

The process cannot access the file
"c:\inetpub\wwwroot\TestPages\Downloads\1243123405 1920061359\585F56645D4740714337170A043006180038060 C017E081A10.doc"
because it is being used by another process.

This shouldn't be a permissions issue because I have full control to
everyone just for testing purposes.

Here is the code snippet:

strTempdirectory = strFileSystemPath & CompanyID & dDateStamp

strFile1 = strFileSystemPath & strFileName

strFile2 = strTempdirectory & "\" & strFileName

If Not Directory.Exists(strTempdirectory) Then

Directory.CreateDirectory(strTempdirectory)

End If

If File.Exists(strFile2) Then

File.Delete(strFile2)

End If

Fails here: ---> File.Copy(strFile1, strFile2, False)

strRedirectPath = strHttpPath & CompanyID & dDateStamp & "/" & strFileName

Response.Redirect(strRedirectPath)



Thanks in advance for any help you might be able to offer.

Ron



 
Reply With Quote
 
 
 
 
RSH
Guest
Posts: n/a
 
      05-19-2006
One recent development...

If I step through the code it works fine...and then each subsequent page
hit works for that file, but if i don't step through the code on a file it
gives me the error.

Thanks,
Ron


"RSH" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I have an ASP .Net web page that creates a temp directory on the server
> then it is using the File.Copy command to move a file to a temp download
> directory, Then I am doing a response.Redirect to that URL.
>
> The problem is that whenever I run the page the script fails on the
> File.Copy() command everytime with an error of:
>
> The process cannot access the file
> "c:\inetpub\wwwroot\TestPages\Downloads\1243123405 1920061359\585F56645D4740714337170A043006180038060 C017E081A10.doc"
> because it is being used by another process.
>
> This shouldn't be a permissions issue because I have full control to
> everyone just for testing purposes.
>
> Here is the code snippet:
>
> strTempdirectory = strFileSystemPath & CompanyID & dDateStamp
>
> strFile1 = strFileSystemPath & strFileName
>
> strFile2 = strTempdirectory & "\" & strFileName
>
> If Not Directory.Exists(strTempdirectory) Then
>
> Directory.CreateDirectory(strTempdirectory)
>
> End If
>
> If File.Exists(strFile2) Then
>
> File.Delete(strFile2)
>
> End If
>
> Fails here: ---> File.Copy(strFile1, strFile2, False)
>
> strRedirectPath = strHttpPath & CompanyID & dDateStamp & "/" & strFileName
>
> Response.Redirect(strRedirectPath)
>
>
>
> Thanks in advance for any help you might be able to offer.
>
> Ron
>
>
>



 
Reply With Quote
 
 
 
 
Tasos Vogiatzoglou
Guest
Posts: n/a
 
      05-19-2006
A very simple thought: Do you close the fileStream ?

 
Reply With Quote
 
RSH
Guest
Posts: n/a
 
      05-19-2006
Im actually not using the filestream. I am just creating the file with:
File.Create(strFileSystemDirectory & strFilename)

Im starting to think it might be a permissions issue...either that or .Net
is not releasing the file.


"Tasos Vogiatzoglou" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>A very simple thought: Do you close the fileStream ?
>



 
Reply With Quote
 
Tasos Vogiatzoglou
Guest
Posts: n/a
 
      05-19-2006
This method opens a FileStream.

 
Reply With Quote
 
RSH
Guest
Posts: n/a
 
      05-19-2006
That fixed it thanks!



"Tasos Vogiatzoglou" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> This method opens a FileStream.
>



 
Reply With Quote
 
Arsalan Ahmad
Guest
Posts: n/a
 
      05-20-2006
Please could you tell me how do you resolve this problem..i m getting same
access problem in writing to a file.

"RSH" <(E-Mail Removed)> wrote in message
news:O3BL2$(E-Mail Removed)...
> That fixed it thanks!
>
>
>
> "Tasos Vogiatzoglou" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>> This method opens a FileStream.
>>

>
>



 
Reply With Quote
 
RSH
Guest
Posts: n/a
 
      05-22-2006

Sure.

Apparently simply calling the File.Create leaves the file in a zombie state.
What you need to do is create and access the file through the declaration of
a StreamWriter object:

Dim sw As StreamWriter = New StreamWriter(strFileSystemDirectory &
strEncodedFileName)

' Add some text to the file.

sw.Write("This is the ")

sw.WriteLine("header for the file.")

sw.WriteLine("-------------------")

' Arbitrary objects can also be written to the file.

sw.Write("The date is: ")

sw.WriteLine(DateTime.Now)

sw.Close()

sw = Nothing



This creates a simple file and writes a few lines of text to it then
disposes the object properly which in turn unlocks the file.

It works great now.



Ron


"Arsalan Ahmad" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Please could you tell me how do you resolve this problem..i m getting same
> access problem in writing to a file.
>
> "RSH" <(E-Mail Removed)> wrote in message
> news:O3BL2$(E-Mail Removed)...
>> That fixed it thanks!
>>
>>
>>
>> "Tasos Vogiatzoglou" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed) oups.com...
>>> This method opens a FileStream.
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 2 11-29-2006 04:30 AM
Cannot delete a file the process cannot access the file because it is being used by another process ASp.net 2 ary ASP .Net 0 11-28-2006 09:13 AM
Process Cannot access file "file_name" because it is being used by another process Rithesh Pai ASP .Net 1 08-22-2005 03:02 PM
Cannot Copy Assembly <MyAssembly> The Process Cannot Access The File Because It Is Being Used By Another Process Ram ASP .Net 2 06-30-2005 11:30 AM
delete file failed, The process cannot access the file because it is being used by another process guoqi zheng ASP .Net 3 04-13-2005 06:17 PM



Advertisments