title: How to insert a file into a filestream data type
body: <p>I am creating an application to store Excel files into a database using the filestream data type provided by SQL Server 2008, and now I'm stuck searching the internet for the best practice way to insert it using a stored procedure from C#.</p>
  
  <p>So far, I've created the database structure and the classes, what I need to do now is to actually use the stored procedure and I'm stuck, here's the snippet of code</p>
  
  <pre><code>OpenFileDialog ofd = new OpenFileDialog();
  ofd.ShowDialog();
  
  if (ofd.CheckFileExists)
  {
      ....            
  }
  
  using (SqlConnection conn = new SqlConnection(Murel.Util.DBUtil.CONSTRING))
  {
      try
      {
          conn.Open();
  
          using (SqlCommand cmd = new SqlCommand("items_insert", conn))
          {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.Add(new SqlParameter("@name", "test"));
             cmd.Parameters.Add(new SqlParameter("@template", HELP));
  
             Guid id = (Guid)cmd.ExecuteScalar();
  
             return true;
          }
       }
       catch (Exception ex)
       {
          throw ex;
       }
       finally
       {
           conn.Close();
       }
    }
  </code></pre>
  
  <p>The data table consist of an <code>id</code> which is an unique identifier, name and template which is <code>varbinary(max)</code>, I already have anything else set up, I just need to know what to put in</p>
  
  <pre><code>cmd.Parameters.Add(new SqlParameter("@template", HELP));
  </code></pre>
  
  <p>thx,</p>
  
  <p>darius</p>