title: Display Word and excel files in web page from database in asp.net c#
body: <p>I have a database where i have saved documents like pdf, word(docx) and excel. I want to display them on web page on view button click. I am able to display pdf file using the below approach.</p>
  
  <pre><code>  string embed = "&lt;object data=\"{0}{1}\" type=\"application/pdf\" width=\"500px\" 
    height=\"600px\"&gt;";
    ltEmbed.Text = string.Format(embed, ResolveUrl("~/Handler1.ashx? 
  id="+id+"&amp;Name="+Name+""), temp);// literal control
  </code></pre>
  
  <p>in Handler1.ashx i have the below</p>
  
  <pre><code> string constr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
              using (SqlConnection con = new SqlConnection(constr))
              {
  
                  using (SqlCommand cmd = new SqlCommand())
                  {
                      cmd.CommandText = "select pdfdoc from repository;
                      cmd.Connection = con;
                      con.Open();
  
                      using (SqlDataReader sdr = cmd.ExecuteReader())
                      {      
                              sdr.Read();
                              bytes = (byte[])sdr["BPM_Doc"];
                      }     
                  }
                      con.Close();
              }
  
              context.Response.Buffer = true;
              context.Response.Charset = "";
              context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
              context.Response.ContentType = "application/pdf";
              context.Response.BinaryWrite(bytes);
              context.Response.End();
  </code></pre>
  
  <p>How can i use the same approach to display word and excel. My word document has images too.</p>