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