Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem using the image box.
when I try to edit the image file on the disk, it don't allow me to edit and gives the following error

The process cannot access the file 'F:\projects\Image Write Demo\Id Card\Id Card\bin\Debug\targetImage.jpg' because it is being used by another process.

please inform me if there is a way to come out of this fix
I am using the file in following code, I think this is the process that occupies the file,

BitmapImage myBitmapImage = new BitmapImage();

myBitmapImage.BeginInit();
imagepath = applicationPath  + "\\targetImage.jpg";

myBitmapImage.UriSource = new Uri(imagepath);

//myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
//set image source
ibTargetImage.Source = myBitmapImage;
Posted
Updated 12-Jan-10 9:09am
v2

BTW, it's much safer to use System.IO.Path.Combine when you're building a path like that.
 
Share this answer
 
John is right. One way or the other, your file is still open somewhere. Does your code open it more than once ? Do you really want to ship your app with a file people can change ? Why not make it a resource ?

And yes, not using Path.Combine is a bit nuts, although I will add that Path.Combine is full of bugs, it is still safer than string mashing.
 
Share this answer
 
I believe your app didn't unload all the way the last time you ran it, and Windows thinks the file is still in use...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900