Search:
Namespaces
Discussions
.NET v1.1
Feedback
The process cannot access the file because it is being used by another process
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngvb' list
.
Darren Patterson
I am trying to copy a file that was uploaded to a temp directory and
when I try to copy it I get the following error:
"The process cannot access the file because it is being used by another
process"
I have closed all associated objects with this file and I am just trying
to move it to a new folder. Here is my code from the sub I am trying to
do this with. This code is from an asp.net codebehind page.
Sub SubCopyFile()
'On Error Goto ErrRoutine
Dim lstrFilePath As String
Dim lstrNewFile As String
Dim lstrOldFileName, lstrNewFileName As String
lstrFilePath =3D
ConfigurationSettings
.AppSettings("FilePath")
lstrNewFile =3D Replace(gstrPostedFile, "raw", "proc")
'move and rename file to the proper directory
If
Directory
.Exists(lstrFilePath & "Uploads\" & gstrICcode & "\POS")
Then
lstrOldFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\Upload\" & gstrPostedFile)
lstrNewFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\POS\" & lstrNewFile)
Trace.Write("Old File " & lstrOldFileName)
Trace.Write("New File " & lstrNewFileName)
Dim lFile As New
FileInfo
(lstrOldFileName)
lFile.MoveTo(lstrNewFileName)
lFile.Delete()
'Rename(lstrOldFileName, lstrNewFileName)
Else
Directory.CreateDirectory(lstrFilePath & "Uploads\" & gstrICcode
+ "\POS")
lstrOldFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\Upload\" & gstrPostedFile)
lstrNewFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\POS\" & lstrNewFile)
Trace.Write("Old File " & lstrOldFileName)
Trace.Write("New File " & lstrNewFileName)
Dim lFile As New
FileInfo
(lstrOldFileName)
lFile.MoveTo(lstrNewFileName)
lFile.Delete()
'Rename(lstrOldFileName, lstrNewFileName)
End If
Exit Sub
ErrRoutine:
Dim errHandler As New clsErrRoutine()
errHandler.SubCatchError("GrowerUpload.aspx.vb", Err.Source, Err.Number,
Err.Description, "")
Err.Clear()
errHandler =3D Nothing
End Sub
Thanks,
Darren
Reply to this message...
Greg Quinn
have you tried putting lFile = nothing in the appropriate places?
Greg
-----Original Message-----
From: Darren Patterson [mailto:
Click here to reveal e-mail address
]
Sent: 26 July 2002 11:00
To: aspngvb
Subject: [aspngvb] The process cannot access the file because it is
being used by another process
I am trying to copy a file that was uploaded to a temp directory and
when I try to copy it I get the following error:
"The process cannot access the file because it is being used by another
process"
I have closed all associated objects with this file and I am just trying
to move it to a new folder. Here is my code from the sub I am trying to
do this with. This code is from an asp.net codebehind page.
Sub SubCopyFile()
'On Error Goto ErrRoutine
Dim lstrFilePath As String
Dim lstrNewFile As String
Dim lstrOldFileName, lstrNewFileName As String
lstrFilePath =
ConfigurationSettings
.AppSettings("FilePath")
lstrNewFile = Replace(gstrPostedFile, "raw", "proc")
'move and rename file to the proper directory
If
Directory
.Exists(lstrFilePath & "Uploads\" & gstrICcode & "\POS")
Then
lstrOldFileName = Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\Upload\" & gstrPostedFile)
lstrNewFileName = Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\POS\" & lstrNewFile)
Trace.Write("Old File " & lstrOldFileName)
Trace.Write("New File " & lstrNewFileName)
Dim lFile As New
FileInfo
(lstrOldFileName)
lFile.MoveTo(lstrNewFileName)
lFile.Delete()
'Rename(lstrOldFileName, lstrNewFileName)
Else
Directory.CreateDirectory(lstrFilePath & "Uploads\" & gstrICcode
+ "\POS")
lstrOldFileName = Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\Upload\" & gstrPostedFile)
lstrNewFileName = Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\POS\" & lstrNewFile)
Trace.Write("Old File " & lstrOldFileName)
Trace.Write("New File " & lstrNewFileName)
Dim lFile As New
FileInfo
(lstrOldFileName)
lFile.MoveTo(lstrNewFileName)
lFile.Delete()
'Rename(lstrOldFileName, lstrNewFileName)
End If
Exit Sub
ErrRoutine:
Dim errHandler As New clsErrRoutine()
errHandler.SubCatchError("GrowerUpload.aspx.vb", Err.Source, Err.Number,
Err.Description, "")
Err.Clear()
errHandler = Nothing
End Sub
Thanks,
Darren
| [aspngvb] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngvb.asp
= JOIN/QUIT
Reply to this message...
Darren Patterson
I am actually getting my error on the line I try to do the .MoveTo
before I can set the lFile =3D Nothing. When I try to delete the file
manually from windows explorer, I also get an error saying another
process is still using the file. Any help would be greatly appreciated.
I use this same code and same process for other files and it works fine,
just this file seems to have trouble when I am done processing it and
try to move it to a permanent directory.
-----Original Message-----
From: Greg Quinn [mailto:
Click here to reveal e-mail address
]=20
Sent: Friday, August 02, 2002 4:55 PM
To: aspngvb
Subject: [aspngvb] RE: The process cannot access the file because it is
being used by another process
have you tried putting lFile =3D nothing in the appropriate places?
Greg
-----Original Message-----
From: Darren Patterson [mailto:
Click here to reveal e-mail address
]
Sent: 26 July 2002 11:00
To: aspngvb
Subject: [aspngvb] The process cannot access the file because it is
being used by another process
I am trying to copy a file that was uploaded to a temp directory and
when I try to copy it I get the following error:
"The process cannot access the file because it is being used by another
process"
I have closed all associated objects with this file and I am just trying
to move it to a new folder. Here is my code from the sub I am trying to
do this with. This code is from an asp.net codebehind page.
Sub SubCopyFile()
'On Error Goto ErrRoutine
Dim lstrFilePath As String
Dim lstrNewFile As String
Dim lstrOldFileName, lstrNewFileName As String
lstrFilePath =3D
ConfigurationSettings
.AppSettings("FilePath")
lstrNewFile =3D Replace(gstrPostedFile, "raw", "proc")
'move and rename file to the proper directory
If
Directory
.Exists(lstrFilePath & "Uploads\" & gstrICcode & "\POS")
Then
lstrOldFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\Upload\" & gstrPostedFile)
lstrNewFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\POS\" & lstrNewFile)
Trace.Write("Old File " & lstrOldFileName)
Trace.Write("New File " & lstrNewFileName)
Dim lFile As New
FileInfo
(lstrOldFileName)
lFile.MoveTo(lstrNewFileName)
lFile.Delete()
'Rename(lstrOldFileName, lstrNewFileName)
Else
Directory.CreateDirectory(lstrFilePath & "Uploads\" & gstrICcode
+ "\POS")
lstrOldFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\Upload\" & gstrPostedFile)
lstrNewFileName =3D Trim(lstrFilePath & "Uploads\" & gstrICcode +
"\POS\" & lstrNewFile)
Trace.Write("Old File " & lstrOldFileName)
Trace.Write("New File " & lstrNewFileName)
Dim lFile As New
FileInfo
(lstrOldFileName)
lFile.MoveTo(lstrNewFileName)
lFile.Delete()
'Rename(lstrOldFileName, lstrNewFileName)
End If
Exit Sub
ErrRoutine:
Dim errHandler As New clsErrRoutine()
errHandler.SubCatchError("GrowerUpload.aspx.vb", Err.Source, Err.Number,
Err.Description, "")
Err.Clear()
errHandler =3D Nothing
End Sub
Thanks,
Darren
| [aspngvb] member
Click here to reveal e-mail address
=3D YOUR ID
|
http://www.asplists.com/asplists/aspngvb.asp
=3D JOIN/QUIT
Reply to this message...
System.Configuration.ConfigurationSettings
System.Diagnostics.Trace
System.IO.Directory
System.IO.FileInfo
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com