• Register
0 votes

Problem :

I have some of the code and when I try to executes it, it throws the below IOException, saying that

“The process cannot access the file 'filename' because it is being used by another process”

What is the meaning of this exception , and how can I completely fix the exception?

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :


I had the below scenarios which was causing the similar error:

· While uploading files to the server

· While getting rid of my old files after they are uploaded to the server.

Most of the files were small in size, however, a few were very large, and so while attempting to delete my files resulted in cannot access file error.

It was not easy for me to find it, but the solution for it was as simple as Waiting "for my task to complete the execution":

using (var mywc = new WebClient())


  var mytskResult = mywc.UploadFileTaskAsync(_address, _fileName);





I also had faced the same issue in the recent past while I was trying to upload my image and I couldn't delete it and found the solution later on it.

//The C# .NET
var myimage = Image.FromFile(filePath);

myimage.Dispose(); // this will remove all resources

//later on...

File.Delete(filePath); //now it works


9 7 4
38,600 points

Related questions

0 votes
1 answer 14 views
Is there any way to check if the file is in use??
asked Sep 8, 2020 Oscar909 460 points
0 votes
1 answer 167 views
Problem : I have received the following error message: The process cannot access the file because another process has locked a portion of the file Cannot open the disk 'C:\Users\t825665\VM's\VPC\Windows 10 x64.vmdk' or one of the snapshot disks it depends on. ... power on failed. Failed to start the virtual machine. I guess my virtual machine is not starting anymore. Any clue how to fix that?
asked Nov 21, 2019 peterlaw 6.9k points
0 votes
1 answer 98 views
Problem : I am facing error on below step objUDMCountryStandards.Country = txtMySearchCountry.Text.Trim() != string.Empty ? txtMySearchCountry.Text : null; in the get grid data throws error as below : “The calling thread cannot access this object because a different thread owns it.” Is there anything wrong with my code?
asked Jan 7, 2020 alecxe 7.5k points
1 vote
1 answer 34 views
Problem : In the following step objUDMCountryStandards.Country = txtSearchCountry.Text.Trim() != string.Empty ? txtSearchCountry.Text : null; in get grid data throws the exception as below : The calling thread cannot access this object because a different thread owns it. What is wrong in my code?
asked Dec 28, 2019 alecxe 7.5k points
0 votes
1 answer 115 views
Problem : I have recently installed a website on my local machine using IIS 7 successfully. But when I tried to deploy it on the live server, I got a following error: "The page cannot be displayed because an internal server error has occurred" Nothing else. Using a same IIS 7 on live and also set to have the Detailed errors in Error Pages module, but still getting a same. What can be the reason?
asked Jan 28, 2020 jwilliam 3.9k points
1 vote
1 answer 41 views
Problem : I want to create the simple user control that should be the slider. When I try to add the AjaxToolkit SliderExtender to my user control I usually get below error: Server Error in '/' Application. The Controls collection cannot be modified because ... control and also tried adding the textbox and the slider extender to my placeholder programmatically but I am still facing the above error.
asked Dec 14, 2019 alecxe 7.5k points
0 votes
1 answer 8 views
8 views asked Oct 8, 2020 miki 1.9k points
0 votes
1 answer 81 views
Problem: I am naïve to C# programming. I am trying to use the auto-implemented properties. I think the best ever way to fix below error is to declare my own backing variable? Please find below my C# code: public Point Origin { get; set; } ... unchanged. To resolve this error, store the result of the expression in an intermediate value, or use a reference type for the intermediate expression.
asked Jul 23, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 325 views
Problem : I am getting into the C# coding but I am having following issue: I have below code on the UserControl: using MyFirstDataLayer.Section1; public class MyFirstClass { protected void MyFirstMethod { MyFirstClass.MyFirstItem oItem = new MyFirstClass.MyFirstItem(); oItem = ... name instead I am not sure of what this actually means, I did some research but was unable to figure it out.
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 31 views
Problem: I am beginner to C#. Please find below my code for your help: public class MySoundManager : MonoBehaviour { public List<AudioSource> audioSounds = new List<AudioSource>(); public double minTime = 0.5; public static void playSound(AudioClip sourceSound, Vector3 objectPosition, int ... to create the object of a class or create a methods as the static one but I don&rsquo;t know how to do it.
asked Jul 22, 2020 Raphael Pacheco 4.9k points