please help me!, delete error of the image files(attached source code)
-
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"); }
-
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"); }
sonic747 wrote:
listBox1.Items.Add(my);
start here, you are adding
BitmapImage
object to yourListBox
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?
-
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"); }
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).
-
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"); }
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 formatsonic747 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
-
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 formatsonic747 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
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).
-
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).
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
-
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
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).
-
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).
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