Had to add an attachment functionality to the project I am currently working on at work.

The snippets below use a simple web service (which I didn’t include) that saves the files uploaded to a database and returns the columns read.

You need at least three columns in the table: ID (PK, int), FILENAME (varchar) and CONTENT (BLOB).

// Attach this method to an upload button.
private void UploadFile(object sender, RoutedEventArgs e)
   OpenFileDialog fileDialog = new OpenFileDialog();
   // In case you want filtering.
   fileDialog.DefaultExt = ".txt";
   fileDialog.Filter = "Text documents (.txt)|*.txt";

   bool? result = fileDialog.ShowDialog();

   if (result == true)
       using (FileStream fs = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read))
           Byte[] b = new Byte[fs.Length];
           fs.Read(b, 0, b.Length);

               // Save the byte array (b) to the BLOB column in the database.
               // I am using a web service.
               WebService.SaveAttachment(Path.GetFileName(fileDialog.FileName), b);
               MessageBox.Show("File uploaded!");
           catch (Exception ex)

Click for the open and download functionalities

This presumes you want to create a transparent overlay layer over all of your elements and center a loading text to the middle of the application.
In my case I had a grid with three rows, hence the Grid.RowSpan="3".


If you change the Canvas name be sure to modify the ElementName in the DockPanel attributes.