Asp.net文本文件从数据库上传和后退

时间:2012-08-21 13:13:00

标签: asp.net file-upload

网络文件上传和以下是用于重写Word和pdf以及xsl等文件的代码但是我没有正确获取文本文件,包括aspx代码也请在下面的fild代码

 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);

{

0 个答案:

没有答案