I have saved files from a data base then used the paths to bind them to my images in my book. But now I need to release those images and rebind with different images. I am not able to delete out the image files that I created to display from the first book that was created. How do I clear the locks on the files so I can recreate them from other images in the database?
This is the code where I create a file for each page of my Tiff file. Then I use this code to try and remove it. But I am not able to remove the file.
The result is always faling in to the Catch and the error is always that the file is in use. Hopefully this helps someone help me.
private void Process_Tiff(BookView wpfbook, string TempFile)
{
RemoveOldFiles();
//Sets each page to an image
Image img = Image.FromFile(TempFile);
int count = img.GetFrameCount(FrameDimension.Page);
List<
BookItem
> MyBook = new List<
BookItem
>();
for (int idx = 0; idx < count; idx++)
{
img.SelectActiveFrame(FrameDimension.Page, idx);
int currentpage = idx + 1;
string TempPageFile = DefaultPath + DocOcc.ToString() + currentpage.ToString() + ".TIFF";
// and then create a new Image from it
img.Save(TempPageFile);
dFile df = new dFile();
df.File_Path = TempPageFile;
FileList.Add(df);
MyBook.Add(new BookItem()
{
Title = TempPageFile
});
}
img.Dispose();
wpfbook.RadBook1.ItemsSource = MyBook;
}
This is the code where I create a file for each page of my Tiff file. Then I use this code to try and remove it. But I am not able to remove the file.
private void RemoveOldFiles()
{
((BookView)((ElementHost)panel1.Controls[0]).Child).RadBook1.ItemsSource = null;
int count = 0;
IList<
dFile
> holddf = new List<
dFile
>();
foreach (dFile dfrow in FileList)
{
try
{
File.Delete(dfrow.File_Path);
count++;
}
catch
{
dFile df = new dFile();
df.File_Path = dfrow.File_Path;
holddf.Add(df);
count++;
}
}
FileList = holddf;
}
The result is always faling in to the Catch and the error is always that the file is in use. Hopefully this helps someone help me.