byte[] mybyte = null; DataTable dt = OrderData.GetFP(txt.Text.Trim()); mybyte = (byte[])dt.Rows[0]["PDF_FILE"]; byte[] fileByte = Convert.FromBase64String(Convert.ToBase64String(mybyte)); Response.Clear(); Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", txt.Text.Trim())); Response.BinaryWrite(mybyte); Response.Flush(); Response.End();
转成 Base64 形式的 System.String:
string a = "base64字符串与普通字符串互转";
byte[] b = System.Text.Encoding.Default.GetBytes(a);
//转成 Base64 形式的 System.String
a = Convert.ToBase64String(b); //YmFzZTY019a3+7Su0+vG1c2o19a3+7Suu6XXqg==
Response.Write(a);
byte[] c = Convert.FromBase64String(a);
a = System.Text.Encoding.Default.GetString(c); //base64字符串与普通字符串互转
Response.Write(a);
使用base64编码的好处