Hi,
In my application i am taking multiple image files from user using openfiledialog and display those image files in flowlayoutpanel. After pressing on Insert button i used to copy all those images in a folder (C:\Images). When there is no file exists the file get copied easily, but if it exists i delete the file, but while deleting file it shows error
"The process cannot access the file"C:\Images\xyz.jpg" because it is being used by another process"
The code i used is
if (File.Exists(destFileName))
{
File.Delete(destFileName);
File.Copy(sourceFileName, destFileName);
}
else
File.Copy(sourceFileName, destFileName);
Is it because i display the images in flowlayoutpanel while deleting. But before execting above code i clears all controls added in the flowlayoutpanel. Still the error occurs.. What should i do?
Regards,
Vidya
Loading
Vidya YadavPosted Oct 7, 2009, 2:07 AM
There is no connections to file anywhere, i input it through openfiledialog but i used to display all images first in flowlayoutpanel and then copy the images to the specified location.
Do the files get used by the flowlayoutpanel when they are added in it, but i clear all controls. "flowlayoutpanel.Controls.Clear();" before copying these images.
Is there any other way to delete the files if they are alrready exists because the error ocurs only when the file exists.
Regards,
Vidya
naura paxPosted Oct 7, 2009, 1:53 AM
I think you should try to find out whether any File connections are kept open in your application.
You can either use using construct for working with connections or at least remove all open connections from memory compulsorily once a read/write operation is over.
Tell me if you couldn't understand it.