0

网络文件上传和以下是用于检索 word 和 pdf 和 xsl 等文件的代码,但没有正确获取包含 aspx 代码的文本文件,也请填写下面的代码

 protected void Button1_Click(object sender, EventArgs e)
    {
        LinkButton lbl = (LinkButton)sender;
        int idee = Convert.ToInt16(lbl.CommandArgument.ToString());
        DataTable dt = new DataTable();            
        con.Open();
        cmd = new SqlCommand("select Name, ContentType, Data from Data_Files where Id=@Id");
        cmd.Parameters.Add("@id", SqlDbType.Int).Value = idee;
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        da.Fill(dt);
        if (dt != null)
        {
            Byte[] bytes = (Byte[])dt.Rows[0]["Data"];
            Response.Buffer = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = dt.Rows[0]["ContentType"].ToString();
            if (dt.Rows[0]["ContentType"].ToString() == "application/vnd.ms-word" || dt.Rows[0]["ContentType"].ToString() == "application/vnd.ms-excel" )
            {
               Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["Name"].ToString());
            }
            Response.BinaryWrite(bytes);

{

4

0 回答 0