protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string id = Request.QueryString["id"].ToString();
            using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString))
            {
        using (SqlCommand cmd = new SqlCommand("select * from Market where , conn))
                {
                    conn.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                       sdr.Read();
                       byte[] myByte = (byte[])sdr["Content"];
                       string filetig = sdr["FName"].ToString().Substring(sdr["Fname"].ToString().LastIndexOf('.'));
                       sdr.Close();
                       string contenttype = "application/octet-stream";    // .*
                       if (filetig == ".jpg" || filetig == ".gif" || filetig == ".emp" || filetig == ".JPG" || filetig == ".GIF" || filetig == ".EMP")
                       {
                           contenttype = "image/GIF";
                        }
                       else if(filetig==".doc" || filetig==".txt")
                       {
                           contenttype = "application/msword";
                       }
                       else if (filetig == ".html")
                       {
                           contenttype = "text/html";
                       }
                       Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                       Response.ContentType = contenttype;
                       Response.Clear();
                       Response.BinaryWrite(myByte);
                       Response.End();
                      }
                }
            }
         }
    }

相关文章:

  • 2022-12-23
  • 2021-05-09
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-01-20
相关资源
相似解决方案