-
June 6th, 2013, 11:35 AM
#1
Command executing method on button click
Hello,
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.
Code:
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);
}
}
}
}
-
June 6th, 2013, 09:46 PM
#2
Re: Command executing method on button click
Move the if statement containing the flg.ShowDialog() call outside the foreach loop.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|