Silverlight: How to break file uploading into a two step process

There are a lot of entries on how to upload files in silverlight, so I won't repeat that code. I will show you how simple it is to turn those examples, which upload immediately after selecting a file, into a two-step process, where you first select a file and then click submit.

It is amazingly simple.

This is what most examples look like:

        private void Browse_Click(object sender, RoutedEventArgs e)
        {
 
            bool? result = dialog.ShowDialog();
            if (result == true)
            {
                   UploadFile();  //Where the painful details are
            }
        }

The first step is to take out UploadFiles() method and put code that will show in a textbox the name of the file:

        private void Browse_Click(object sender, RoutedEventArgs e)
        {
 
            bool? result = dialog.ShowDialog();
            if (result == true)
            {
                  textSelectedFile.Text = dialog.File.Name;
            }
        }

The second and last step is to populate the event for the upload button with the UploadFile() method. Notice that the method must check that the dialog.File object is not set to null.

  private void Upload_Click(object sender, RoutedEventArgs e)
        {
            if (dialog.File != null)
            {
                    UploadFile();         //Painful details moved here!
            }
        }

And that is all. Easy, isn't it?