473,287 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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

RSH
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

May 19 '06 #1
7 23163
RSH
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" <wa*************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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

May 19 '06 #2
A very simple thought: Do you close the fileStream ?

May 19 '06 #3
RSH
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" <tv*****@gmail.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
A very simple thought: Do you close the fileStream ?

May 19 '06 #4
This method opens a FileStream.

May 19 '06 #5
RSH
That fixed it thanks!

"Tasos Vogiatzoglou" <tv*****@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
This method opens a FileStream.

May 19 '06 #6
Please could you tell me how do you resolve this problem..i m getting same
access problem in writing to a file.

"RSH" <wa*************@yahoo.com> wrote in message
news:O3**************@TK2MSFTNGP04.phx.gbl...
That fixed it thanks!

"Tasos Vogiatzoglou" <tv*****@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
This method opens a FileStream.


May 20 '06 #7
RSH

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" <ar*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Please could you tell me how do you resolve this problem..i m getting same
access problem in writing to a file.

"RSH" <wa*************@yahoo.com> wrote in message
news:O3**************@TK2MSFTNGP04.phx.gbl...
That fixed it thanks!

"Tasos Vogiatzoglou" <tv*****@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
This method opens a FileStream.



May 22 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Henrik | last post by:
How do you access another window? For example if u whant tpo write something in a textbox in an other opwn window?
2
by: Ingvar Nilsen | last post by:
What I want is to have an ASP.Net web application access another web page (not a web service), get the response content from this, do something with it and send it back to the client. Have...
9
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit...
2
by: Homer J. Simpson | last post by:
Hi there, Does anyone know a working tip to avoid an external js file being cached, whathever the client cache policy is ? Thanks in advance, J. Philippe
2
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to...
2
by: terry | last post by:
Hi, I am using a FrameSet with three frames. In server code (c# code behind) is it possible for a page to call a function in another page of the frameset? I suspect that it is not possible but...
1
by: crka.crka | last post by:
Does anyone know a way to prevent a file being deleted so the only way to delete is via unistallation? Help would be very much appreciated.
10
by: vunet.us | last post by:
What is the workaround of passign a parameter to any included asp file: <!-- #Include File="file.asp" --> This obviously does not work: <!-- #Include File="file.asp?id=123" --> Thank you
9
by: tshad | last post by:
I am trying to get access to a file that may still being written because the file is so large (7-10MB). I get an error: The process cannot access the file 'c:\TestDocs\XMLFiles\492172.XML'...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.