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 'ngfx-io' list
.
Darren Patterson
-- Copied from [aspngvb] to [ngfx-io] by Let the good times roll <
Click here to reveal e-mail address
> --
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
Reply to this message...
Darren Patterson
Does anyone know how to find out what process is holding a file or
another object that I want to do something with but can't because
another process is holding it? I want to find a way to either know the
identity of the process holding or a way to kill it so my code can
finish with what it needs to do.
-----Original Message-----
From: Darren Patterson=20
Sent: Friday, July 26, 2002 2:00 PM
To: ngfx-io
Subject: [ngfx-io] The process cannot access the file because it is
being used by another process
-- Copied from [aspngvb] to [ngfx-io] by Let the good times roll
<
Click here to reveal e-mail address
> --
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
| [ngfx-io] member
Click here to reveal e-mail address
=3D YOUR ID
|
http://www.aspfriends.com/aspfriends/ngfx-io.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