Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem deleting file after loading in imagelist..

Problem deleting file after loading in imagelist..

Scheduled Pinned Locked Moved C#
helpcode-review
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abcxyz82
    wrote on last edited by
    #1

    Hi all, My application loads user selected images in Imagelist for thumbnail display in Listview...Here's the code that i use do that.. ImageList.Images.Add(imageToLoad,Image.FromFile(imageToLoad)); LstVwImage.Items.Add(imageToLoad,imageToLoad); So far so good, When user selects any image from listview and selects Delete button, I want it to remove items from listview and imagelist and delete physical file corrosponding that path, here's the code I am using... LstVwImage.Items.RemoveAt(deleteIndex); ImageList.Images.RemoveAt(deleteIndex); FileInfo fi = new FileInfo(deleteFile); fi.Delete(); Unfortunately its not able to delete file, saying "File is being used by another process"...Its not permission error as I am able to delete any file if its not loaded in imagelist or listview... Either I'm getting crazy or stupid error!!! Pls throw some light on this!! Regards MaulikCE "Every obstacle presents an opportunity to improve our condition."

    _ 1 Reply Last reply
    0
    • A abcxyz82

      Hi all, My application loads user selected images in Imagelist for thumbnail display in Listview...Here's the code that i use do that.. ImageList.Images.Add(imageToLoad,Image.FromFile(imageToLoad)); LstVwImage.Items.Add(imageToLoad,imageToLoad); So far so good, When user selects any image from listview and selects Delete button, I want it to remove items from listview and imagelist and delete physical file corrosponding that path, here's the code I am using... LstVwImage.Items.RemoveAt(deleteIndex); ImageList.Images.RemoveAt(deleteIndex); FileInfo fi = new FileInfo(deleteFile); fi.Delete(); Unfortunately its not able to delete file, saying "File is being used by another process"...Its not permission error as I am able to delete any file if its not loaded in imagelist or listview... Either I'm getting crazy or stupid error!!! Pls throw some light on this!! Regards MaulikCE "Every obstacle presents an opportunity to improve our condition."

      _ Offline
      _ Offline
      _eulogy_
      wrote on last edited by
      #2

      I guess it is that the image hasn't been garbage collected yet, so the image file isn't closed.. You should try to call the Dispose method of the image before the delete function is called..

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups