We help IT Professionals succeed at work.
Get Started

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

85 Views
Last Modified: 2020-03-11
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

Open in new window


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

Open in new window


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

Wayne
Comment
Watch Question
Author, Web Developer
CERTIFIED EXPERT
Top Expert 2009
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE