This is a migrated thread and some comments may be shown as answers.

Unlocking files

1 Answer 31 Views
Book
This is a migrated thread and some comments may be shown as answers.
Bret
Top achievements
Rank 1
Bret asked on 31 Jan 2012, 06:59 PM
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?

 

 

 

 

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.

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 03 Feb 2012, 08:42 AM
Hello Bret,

 Could you please check out this forum posts and let us know if they are helpful?
Load Image Without Locking File
Problems overwriting image when it was set as image source

Kind regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Book
Asked by
Bret
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or