打开存储在db中的pdf文件作为二进制数据

时间:2013-12-04 13:23:11

标签: c# .net

如果我将pdf文件存储在sql server中作为二进制数据,varbinary(MAX)如何检索它以打开该文件?

我有以下

if(myObject.PdfFile != null)
{
   MemoryStream ms = new MemoryStream(myObject.PdfFile);
   // what to do with this ms to open file?
}

4 个答案:

答案 0 :(得分:2)

您可以使用 HttpResponse BinaryWrite方法

   var bytes = reader.GetSqlBytes(index);
    Response.BinaryWrite(bytes.Value);

答案 1 :(得分:2)

以下代码行对您有所帮助。 “myobject”是具有proerties Attach_name,Attach_Type等的类文件.Atand_Doc是byte []类型的属性。

Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" + myobject.ATTACH_NAME);
Response.ContentType = myObject.ATTACH_TYPE;// doc.DOCUMENT_TYPE;
Response.BinaryWrite((byte[])myObject.ATTACH_DOC);
Response.Flush();
Response.End();

答案 2 :(得分:0)

您必须调用存储过程或内联查询来选择varbinary列。

然后将byte []保存到扩展名为.pdf

的文件中

然后你使用进程用adobe reader打开pdf

答案 3 :(得分:0)

如果不想劫持其他答案但要澄清......如果您的应用程序是Web应用程序/网页,那么user1081802和SpiderCode说您可以使用

Response.BinaryWrite 

但是,如果它不是一个Web应用程序,那么您需要将二进制数据作为文件保存到硬盘中,然后从那里打开它作为liquidnake786建议。

相关问题