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




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