我正在尝试检索二进制数据[PDF]从SQL Server到我的虚拟目录:
string filePaths = System.Web.HttpContext.Current.Server.MapPath("~/TempPDF/");
我有以下代码将数据写入filePath,它的下载很好,但是当我试图在PDF中打开它给我错误。 " Adobe Reader无法打开 " FileName.pdf"因为它不受支持或文件已被损坏" 我的代码:
string last = fileName.Substring(fileName.LastIndexOf('.') + 1);
if (last == "pdf")
{
using (System.IO.FileStream fs = new System.IO.FileStream(filePaths+fileName, System.IO.FileMode.CreateNew ))
{ // use a binary writer to write the bytes to disk
using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
{
bw.Write(Data, 0, Data.Length);
//bw.Write(Data);
bw.Flush();
bw.Close();
}
}
}