Unlocking files

2 posts, 0 answers
  1. Bret
    Bret avatar
    14 posts
    Member since:
    May 2011

    Posted 31 Jan 2012 Link to this post

    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)
        //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
            dFile df = new dFile();
            df.File_Path = TempPageFile;
            MyBook.Add(new BookItem()
                Title = TempPageFile
        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)
               dFile df = new dFile();
               df.File_Path = dfrow.File_Path;
        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.

  2. Petar Mladenov
    Petar Mladenov avatar
    2882 posts

    Posted 03 Feb 2012 Link to this post

    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 >>

  3. DevCraft R3 2016 release webinar banner
Back to Top