title: Upload and download files on SQL Server from a C# application
body: <p>I have a C# application that is uploading files to a sql server, I use this code to get the pdf file and then I change it to "bytes" for upload on the SQL Server database.</p>
  
  <pre><code>private void mButtonAddCV_Click(object sender, EventArgs e)
  {
      openFileDialog1.Filter = "PDF Files | *.pdf";
      if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
          if (openFileDialog1.FileName.Length &gt; 0)
          {
              pathCV = openFileDialog1.FileName;
          }
      }
  
      // Read the file and convert it to Byte Array
      string filePath = pathCV;
      string contenttype = String.Empty;
  
      contenttype = "application/pdf";
  
      if (contenttype != String.Empty)
      {
          Stream fs = File.OpenRead(filePath);
          BinaryReader br = new BinaryReader(fs);
          bytes = br.ReadBytes((Int32)fs.Length);
      }
  }
  </code></pre>
  
  <p>I use the code below to upload the file: </p>
  
  <pre><code>if (!mConnector.Update("INSERT INTO **** (***, ***, CV) " +
                              "VALUES ('" + *** + "', '" + *** + "', '" + bytes + "')"))
  {
      Messages.errorMessageBox("This CV already exists.");
  }
  else
  {
      ChangeScreen(ActiveScreen, ActiveScreens.ActiveScreen_CVList);
  }
  </code></pre>
  
  <p>But now I don't know how to download this file and how to make a pdf file with the data stored on the database to see it. Can anyone help me? </p>
  
  <p>Thanks!</p>