.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification