troubleshooting Question

FileSystem.MoveFile - System.IO.IOException: The process cannot access the file because it is being used by another process.

Avatar of Wayne Barron
Wayne BarronFlag for United States of America asked on
Visual Basic.NETMicrosoft IIS Web Server
1 Comment1 Solution93 ViewsLast Modified:
Hello All;

I have a file move issue that only started because I had to take a sub-folder on my site, and [convert to Application]

Here is a portion of the code I am using.
            For Each postedFile As HttpPostedFile In filMyFile.PostedFiles
                Dim getfile As String = System.IO.Path.GetFileName(postedFile.FileName)
                Dim FileToMove As String
                Dim MoveLocation As String

                           GlobalVariables.savepath = Context.Server.MapPath("../Media/Temp/")
                           GlobalVariables.MovePath = Context.Server.MapPath("../Media/")


                            FileToMove = (GlobalVariables.savepath & getfile & ".mp3")
                            MoveLocation = (GlobalVariables.MovePath & strPath & "/" & getfile & ".mp3")


                            If System.IO.File.Exists(FileToMove) = True Then
                                My.Computer.FileSystem.MoveFile(FileToMove, MoveLocation) ' <<<< ERROR POINTS HERE
                            End If

The code was working correctly until I changed the sub-folder to [convert to Application]
Once I did that, I received this error.

Permissions are correctly given for the folder, so it does not seem to be a permissions issue.
I used Windows Resource Monitor.
Chose the CPU tab.
Searched for mp3 in the [Associated Handles]
Here is one line from the results of the search


Image                PID      Type      Handle Name
w3wp.exe      12272      File             G:\InetPub\wwwroot\mysite\Media\Temp\03112020223702438.mp3

I read that I needed to close the opened file.
I tried to do.
mp3.Dispose() ' did nothing
filMyFile.Dispose() ' did nothing

Any other suggestions to help get past this issue, so it will go back to working correctly?
Thanks.

Wayne
ASKER CERTIFIED SOLUTION
Wayne Barron
Author, Web Developer
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros