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. please help me!, delete error of the image files(attached source code)

please help me!, delete error of the image files(attached source code)

Scheduled Pinned Locked Moved C#
csharphelpwpfworkspace
8 Posts 4 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.
  • S Offline
    S Offline
    sonic747
    wrote on last edited by
    #1

    i want delete image file. very well insert image file to listbox. but, do not delete image file , please, take me a error,, attached the source project files, reply send to me(sonic747@esolgorup.co.kr) ---env c#, wpf, .net3.5 /.... source file download //imagefile insert to listbox/// private void button1_Click(object sender, RoutedEventArgs e) { savepath = System.Environment.CurrentDirectory.ToString(); foreach (string f in Directory.GetFiles(savepath + "/image", "*.jpg")) { BitmapImage my; my= new BitmapImage(); my.BeginInit(); my.CacheOption = BitmapCacheOption.OnLoad; my.UriSource = new Uri(f, UriKind.RelativeOrAbsolute); my.EndInit(); listBox1.Items.Add(my); } } /////////delete image file (error) /// private void button2_Click(object sender, RoutedEventArgs e) { string makestr1, item1; item1 = listBox1.Items[0].ToString(); makestr1 = item1.Substring(8, item1.Length - 8); listBox1.Items.Remove(listBox1.Items[0]); if (System.IO.File.Exists(makestr1)) { System.IO.File.Delete(makestr1); //<--error point } else MessageBox.Show("Nothingfile"); }

    L Y D 3 Replies Last reply
    0
    • S sonic747

      i want delete image file. very well insert image file to listbox. but, do not delete image file , please, take me a error,, attached the source project files, reply send to me(sonic747@esolgorup.co.kr) ---env c#, wpf, .net3.5 /.... source file download //imagefile insert to listbox/// private void button1_Click(object sender, RoutedEventArgs e) { savepath = System.Environment.CurrentDirectory.ToString(); foreach (string f in Directory.GetFiles(savepath + "/image", "*.jpg")) { BitmapImage my; my= new BitmapImage(); my.BeginInit(); my.CacheOption = BitmapCacheOption.OnLoad; my.UriSource = new Uri(f, UriKind.RelativeOrAbsolute); my.EndInit(); listBox1.Items.Add(my); } } /////////delete image file (error) /// private void button2_Click(object sender, RoutedEventArgs e) { string makestr1, item1; item1 = listBox1.Items[0].ToString(); makestr1 = item1.Substring(8, item1.Length - 8); listBox1.Items.Remove(listBox1.Items[0]); if (System.IO.File.Exists(makestr1)) { System.IO.File.Delete(makestr1); //<--error point } else MessageBox.Show("Nothingfile"); }

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      sonic747 wrote:

      listBox1.Items.Add(my);

      start here, you are adding BitmapImage object to your ListBox

      sonic747 wrote:

      item1 = listBox1.Items[0].ToString();

      what do you get when you do ToString() on that object? huh? Got Clue? :rolleyes:

      Yusuf May I help you?

      1 Reply Last reply
      0
      • S sonic747

        i want delete image file. very well insert image file to listbox. but, do not delete image file , please, take me a error,, attached the source project files, reply send to me(sonic747@esolgorup.co.kr) ---env c#, wpf, .net3.5 /.... source file download //imagefile insert to listbox/// private void button1_Click(object sender, RoutedEventArgs e) { savepath = System.Environment.CurrentDirectory.ToString(); foreach (string f in Directory.GetFiles(savepath + "/image", "*.jpg")) { BitmapImage my; my= new BitmapImage(); my.BeginInit(); my.CacheOption = BitmapCacheOption.OnLoad; my.UriSource = new Uri(f, UriKind.RelativeOrAbsolute); my.EndInit(); listBox1.Items.Add(my); } } /////////delete image file (error) /// private void button2_Click(object sender, RoutedEventArgs e) { string makestr1, item1; item1 = listBox1.Items[0].ToString(); makestr1 = item1.Substring(8, item1.Length - 8); listBox1.Items.Remove(listBox1.Items[0]); if (System.IO.File.Exists(makestr1)) { System.IO.File.Delete(makestr1); //<--error point } else MessageBox.Show("Nothingfile"); }

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Again? You can't delete an image that is in use. And it remains in use until you: - remove all references to it (as in ListBox.Items) - AND call Dispose() on that image And please show code snippets inside PRE tags. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read formatted code with indentation, so please use PRE tags for code snippets.


        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


        1 Reply Last reply
        0
        • S sonic747

          i want delete image file. very well insert image file to listbox. but, do not delete image file , please, take me a error,, attached the source project files, reply send to me(sonic747@esolgorup.co.kr) ---env c#, wpf, .net3.5 /.... source file download //imagefile insert to listbox/// private void button1_Click(object sender, RoutedEventArgs e) { savepath = System.Environment.CurrentDirectory.ToString(); foreach (string f in Directory.GetFiles(savepath + "/image", "*.jpg")) { BitmapImage my; my= new BitmapImage(); my.BeginInit(); my.CacheOption = BitmapCacheOption.OnLoad; my.UriSource = new Uri(f, UriKind.RelativeOrAbsolute); my.EndInit(); listBox1.Items.Add(my); } } /////////delete image file (error) /// private void button2_Click(object sender, RoutedEventArgs e) { string makestr1, item1; item1 = listBox1.Items[0].ToString(); makestr1 = item1.Substring(8, item1.Length - 8); listBox1.Items.Remove(listBox1.Items[0]); if (System.IO.File.Exists(makestr1)) { System.IO.File.Delete(makestr1); //<--error point } else MessageBox.Show("Nothingfile"); }

          D Offline
          D Offline
          Dr Walt Fair PE
          wrote on last edited by
          #4

          So, what is the error message and what is the value of makestr1 when it gives the error? It would be easier to read if you use <pre> tags to format

          sonic747 wrote:

          reply send to me(xxxx@yyyyy.zzzz)

          Good luck with that!

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          modified on Tuesday, May 18, 2010 10:26 PM

          L 1 Reply Last reply
          0
          • D Dr Walt Fair PE

            So, what is the error message and what is the value of makestr1 when it gives the error? It would be easier to read if you use <pre> tags to format

            sonic747 wrote:

            reply send to me(xxxx@yyyyy.zzzz)

            Good luck with that!

            CQ de W5ALT

            Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

            modified on Tuesday, May 18, 2010 10:26 PM

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Yikes, publishing someone's e-mail address is very naughty. He could still have removed it in his message, but he can't change yours though. It is *not* fair. :|

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


            D 1 Reply Last reply
            0
            • L Luc Pattyn

              Yikes, publishing someone's e-mail address is very naughty. He could still have removed it in his message, but he can't change yours though. It is *not* fair. :|

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              D Offline
              D Offline
              Dr Walt Fair PE
              wrote on last edited by
              #6

              Yes, Luc, you're right. Thanks for pointing that out -- I've modified my message. I honestly wasn't paying attention.

              CQ de W5ALT

              Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

              L 1 Reply Last reply
              0
              • D Dr Walt Fair PE

                Yes, Luc, you're right. Thanks for pointing that out -- I've modified my message. I honestly wasn't paying attention.

                CQ de W5ALT

                Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Now you're again being the fair person we are used to. ;P

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read formatted code with indentation, so please use PRE tags for code snippets.


                I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                D 1 Reply Last reply
                0
                • L Luc Pattyn

                  Now you're again being the fair person we are used to. ;P

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read formatted code with indentation, so please use PRE tags for code snippets.


                  I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                  D Offline
                  D Offline
                  Dr Walt Fair PE
                  wrote on last edited by
                  #8

                  Well, I try ... and sometimes do a fair job of it. ;P

                  CQ de W5ALT

                  Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

                  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