Command executing method on button click
I have the below method that takes binary data from sql server, stores it in a observable collection and writes the files to a folder. The problem is when the user clicks the dialog ok button, the ok button has to be clicked for every file in the collection. So if the collection has 5 files that need to be saved the button must be clicked 5 times. I am doing this in a c# wpf app using linq to sql.
How can this be handled with just one click?
A relay command is executing this function and the command is bound to the button in xaml.
private void executeSaveAttachments(object parameter)
System.Windows.Forms.FolderBrowserDialog flg = new System.Windows.Forms.FolderBrowserDialog();
foreach (var table in Table)
if (flg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
File.WriteAllBytes(Path.Combine(flg.SelectedPath, table.Title + ".xlsx"), table.Data);
Re: Command executing method on button click
Move the if statement containing the flg.ShowDialog() call outside the foreach loop.