CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Question 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);
    
                        }
                    }
                }
            }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
  •  





Click Here to Expand Forum to Full Width

Featured