Link to home
Start Free TrialLog in
Avatar of soorraj
soorrajFlag for United States of America

asked on

Getting this error "The process cannot access the file because it is being used by another process" Image File ASP.NET , WIN FORMS, C#

I am getting this error "The process cannot access the file because it is being used by another process " when i try to overwrite an image.

I have a Data grid, when i click on the data grid record the image comes up. Then i have a capture button that takes the picture.

If i want to retake the image the error pops up. "The process cannot access the file because it is being used by another process "

I can insert the image fine when i try to overwrite the existing image it is not working.

When the User clicks on the DataGrid Record the public void GetIMage() is called.

When the user click on the capture button the
private void btnSnapshot_Click is called

I tried to check if the image is already there then delete it and save the new image and still it doesn''t work.

I have attached the codes below It is WIN FORMS ASP.NET C#
Image.txt
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of soorraj

ASKER

It still gives the same error. How will i do it in my code. I tried to do this way

 string imagePathApple = System.IO.Path.Combine(LoadPath);
if (System.IO.File.Exists(imagePathApple))
                    {

                        System.IO.FileStream fs = new System.IO.FileStream(imagePathApple, System.IO.FileMode.Open);
                        PhotoPictureBox.Image = Image.FromStream(fs);
                        fs.Close();
image.Save(LoadPath, ImageFormat.Jpeg);
}

                       


                    }

 else
                   {
                       image.Save(LoadPath, ImageFormat.Jpeg);
                    }
This line:

    image.Save(LoadPath, ImageFormat.Jpeg);

was in a completely different method from your original post...   =\

How is "image" getting populated?  Show more complete code that you are currently attempting to use.
Avatar of soorraj

ASKER

Thanks for your help.