Downloaded file is corrupt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newface
    New Member
    • Feb 2012
    • 16

    Downloaded file is corrupt

    Code:
    string SQL = "SELECT FileName,FileSize,ContentType,FileData FROM FileTable WHERE FileID = '" + FileID + "'";
            SqlConnection con = Connection.GetConnection();
            SqlCommand cmd = new SqlCommand();
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(SQL, con);
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            da.Fill(dt);
            Byte[] bytes = System.Text.Encoding.Unicode.GetBytes(dt.Rows[0][3].ToString());
            Response.Buffer = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = dt.Rows[0][2].ToString();
            Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0][0].ToString());
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    It's nice that you've provided code, and put it in code tags even, but you've given no information on what the issue is, any error messages you're getting or anything.

    You stand a better chance of getting help if you edit your post and tell us what the issue is.

    Comment

    • Newface
      New Member
      • Feb 2012
      • 16

      #3
      The file is corrupt and con not be opended

      I am trying download any specific file from database through this code.the issue is after execution of this code file is downloaded but if click open,it shows "the file is corrupt and con not be opended"


      Originally posted by Richard McCutchen
      It's nice that you've provided code, and put it in code tags even, but you've given no information on what the issue is, any error messages you're getting or anything.

      You stand a better chance of getting help if you edit your post and tell us what the issue is.

      Comment

      Working...