WriteFile,BinaryWrite,OutputStream ......都无法正常工作 [英] WriteFile, BinaryWrite, OutputStream.. all not working

查看:50
本文介绍了WriteFile,BinaryWrite,OutputStream ......都无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有我能想到的Response方法(WriteFile,

BinaryWrite,OutputStream)来将pdf文件的字节数组写入

响应。结果看起来像是在尝试,它出现了一个空白的PDF

文件(没有通常出现的Adobe工具栏)。这是代码我

我正在使用...


''... fPDF是我的字节数组

'' ...我已经通过将数组写入物理

文件(result.pdf)并手动打开它来验证它是有效的

'' ----------------------------------------------

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType =" application / pdf"


''...尝试WriteFile

Response.WriteFile("〜/ xml / result.pdf")


''...尝试BinaryWrite

Response.BinaryWrite(fPDF)


''...尝试OutputStream

Response.OutputStream.Write(fPDF, 0,fPDF.Length)

Response.Flush()

Response.Close()

''-------- ------------------------------------


是吗?可能是因为请求的页面有* .aspx扩展名?如果它是
,有没有办法解决这个问题?

I have tried all the Response methods I can think of (WriteFile,
BinaryWrite, OutputStream) to write the byte array of a pdf file to the
response. The result looks like it''s trying, it comes up as a blank PDF
file (without the Adobe toolbar that normally comes up). Here is the code I
am using...

''...fPDF is my Byte array
''...I''ve already verified it is valid by writing the array to a physical
file ("result.pdf") and opening it manually
''----------------------------------------------
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

''...trying WriteFile
Response.WriteFile("~/xml/result.pdf")

''...trying BinaryWrite
Response.BinaryWrite(fPDF)

''...trying OutputStream
Response.OutputStream.Write(fPDF, 0, fPDF.Length)
Response.Flush()
Response.Close()
''--------------------------------------------

Is it possibly because the requested page has the *.aspx extension? If it
is, is there a way around this?

推荐答案




我建议添加内容处理以确保浏览器

实际上知道它是二进制下载。


我已经只是做了测试,它的工作原理!


Response.ContentType =" application / pdf"

Response.AddHeader(" content-disposition"," ; attachment; filename = file.pdf")

Response.WriteFile(" file.pdf")


希望有所帮助。


--------------------------

Jean-Claude Morin,MCP
软件开发人员

2k1Soft / kCentric,加拿大

随机 < CI ******* @ hotmail.com>在留言中写道

新闻:O7 **************** @ TK2MSFTNGP09.phx.gbl ...
Hi,

I would suggest to add the content disposition to make sure the browser
actually knows it''s a binary download.

I''ve just did the test and it works!

Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=file.pdf")
Response.WriteFile("file.pdf")

Hope that help.

--------------------------
Jean-Claude Morin, MCP
Software Developer
2k1Soft/kCentric, Canada
"Random" <ci*******@hotmail.com> wrote in message
news:O7****************@TK2MSFTNGP09.phx.gbl...
我试过我能想到的所有Response方法(WriteFile,
BinaryWrite,OutputStream)都将pdf文件的字节数组写入
响应。结果看起来像是在尝试,它出现了一个空白的PDF
文件(没有通常出现的Adobe工具栏)。这是我正在使用的代码
...

''... fPDF是我的字节数组
''我已经验证它是有效的将数组写入物理
文件(result.pdf)并手动打开
''-------------------- --------------------------
Response.ClearContent()
Response.ClearHeaders()
响应。 ContentType =" application / pdf"

''...尝试WriteFile
Response.WriteFile("〜/ xml / result.pdf")

''...尝试BinaryWrite
Response.BinaryWrite(fPDF)
''...尝试OutputStream
Response.OutputStream.Write(fPDF,0,fPDF.Length)
Response.Flush()
Response.Close()
''-------------------------- ------------------

是否可能是因为请求的页面有* .aspx扩展名?如果它是,有没有办法解决这个问题?
I have tried all the Response methods I can think of (WriteFile,
BinaryWrite, OutputStream) to write the byte array of a pdf file to the
response. The result looks like it''s trying, it comes up as a blank PDF
file (without the Adobe toolbar that normally comes up). Here is the code I am using...

''...fPDF is my Byte array
''...I''ve already verified it is valid by writing the array to a physical
file ("result.pdf") and opening it manually
''----------------------------------------------
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

''...trying WriteFile
Response.WriteFile("~/xml/result.pdf")

''...trying BinaryWrite
Response.BinaryWrite(fPDF)

''...trying OutputStream
Response.OutputStream.Write(fPDF, 0, fPDF.Length)
Response.Flush()
Response.Close()
''--------------------------------------------

Is it possibly because the requested page has the *.aspx extension? If it
is, is there a way around this?



你的实际失败是什么?


是不下载还是显示内容?


确保hte内容也有效 - 您可以尝试下载

将HttpWebRequest内容添加到文件中并查看内容是否确实如果您在运行中生成PDF,则确实有效。


+++ Rick - -


-


Rick Strahl

West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/

----------------------------------

网页

"随机& QUOT; < CI ******* @ hotmail.com>在消息中写道

新闻:O7 ************** @ TK2MSFTNGP09.phx.gbl ...
What is your actual failure?

Is it not downloading or is it displaying the content?

Make sure that hte content is valid also - you might try downloading the
content with HttpWebRequest to a file and seeing if the content is indeed
valid if you were generating the PDF on the fly.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"Random" <ci*******@hotmail.com> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...
我试过所有的我能想到的响应方法(WriteFile,
BinaryWrite,OutputStream)将pdf文件的字节数组写入
响应。结果看起来像是在尝试,它出现了一个空白的PDF
文件(没有通常出现的Adobe工具栏)。这是我正在使用的代码
...

''... fPDF是我的字节数组
''我已经验证它是有效的将数组写入物理
文件(result.pdf)并手动打开
''-------------------- --------------------------
Response.ClearContent()
Response.ClearHeaders()
响应。 ContentType =" application / pdf"

''...尝试WriteFile
Response.WriteFile("〜/ xml / result.pdf")

''...尝试BinaryWrite
Response.BinaryWrite(fPDF)
''...尝试OutputStream
Response.OutputStream.Write(fPDF,0,fPDF.Length)
Response.Flush()
Response.Close()
''-------------------------- ------------------

是否可能是因为请求的页面有* .aspx扩展名?如果它是,是否有办法解决这个问题?
I have tried all the Response methods I can think of (WriteFile,
BinaryWrite, OutputStream) to write the byte array of a pdf file to the
response. The result looks like it''s trying, it comes up as a blank PDF
file (without the Adobe toolbar that normally comes up). Here is the code I am using...

''...fPDF is my Byte array
''...I''ve already verified it is valid by writing the array to a physical
file ("result.pdf") and opening it manually
''----------------------------------------------
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

''...trying WriteFile
Response.WriteFile("~/xml/result.pdf")

''...trying BinaryWrite
Response.BinaryWrite(fPDF)

''...trying OutputStream
Response.OutputStream.Write(fPDF, 0, fPDF.Length)
Response.Flush()
Response.Close()
''--------------------------------------------

Is it possibly because the requested page has the *.aspx extension? If it
is, is there a way around this?



嗯,这使得pdf下载得很好。现在的问题是,我得到了下载或保存这个下载或保存的信息。对话框和文件在Acrobat中打开。我想在浏览器窗口中显示



" Jc Morin" < MI **************** @ jcmorin.net>在消息中写道

news:%2 *************** @ TK2MSFTNGP15.phx.gbl ...
Well, that got the pdf to download fine. The problem now is, I''m getting
the "download or save" dialog and the file is opening in Acrobat. I''d like
it to display in the browser window.
"Jc Morin" <mi****************@jcmorin.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...


我建议添加内容处理,以确保浏览器确实知道它是二进制下载。

我刚刚做了测试,它有效!

Response.ContentType =" application / pdf"
Response.AddHeader(" content-disposition"," attachment; filename = file.pdf")
Response.WriteFile(" file.pdf")

希望有所帮助。

------------------ --------
Jean-Claude Morin,MCP
软件开发人员
2k1Soft / kCentric,加拿大

" Random" < CI ******* @ hotmail.com>在消息中写道
新闻:O7 **************** @ TK2MSFTNGP09.phx.gbl ...
Hi,

I would suggest to add the content disposition to make sure the browser
actually knows it''s a binary download.

I''ve just did the test and it works!

Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=file.pdf")
Response.WriteFile("file.pdf")

Hope that help.

--------------------------
Jean-Claude Morin, MCP
Software Developer
2k1Soft/kCentric, Canada
"Random" <ci*******@hotmail.com> wrote in message
news:O7****************@TK2MSFTNGP09.phx.gbl...
我已经尝试了所有的Response方法我可以想(WriteFile,
BinaryWrite,OutputStream)将pdf文件的字节数组写入
响应。结果看起来像是在尝试,它出现了一个空白的PDF
文件(没有通常出现的Adobe工具栏)。这是
代码
I have tried all the Response methods I can think of (WriteFile,
BinaryWrite, OutputStream) to write the byte array of a pdf file to the
response. The result looks like it''s trying, it comes up as a blank PDF
file (without the Adobe toolbar that normally comes up). Here is the
code


正在使用...

''... fPDF是我的字节数组
''...我已经通过将数组写入物理
文件(result.pdf)并手动打开它来验证它是否有效
''---- ------------------------------------------
Response.ClearContent( )
Response.ClearHeaders()
Response.ContentType =" application / pdf"

''...尝试WriteFile
Response.WriteFile("〜 /xml/result.pdf")

''...尝试BinaryWrite
Response.BinaryWrite(fPDF)

''...尝试OutputStream
Response.OutputStream.Write(fPDF,0,fPDF.Length)
Response.Flush()
Response.Close()
''---------- ----------------------------------

是否可能是因为请求的页面有* .aspx扩展名?如果
它是,有没有办法解决这个问题?
am using...

''...fPDF is my Byte array
''...I''ve already verified it is valid by writing the array to a physical
file ("result.pdf") and opening it manually
''----------------------------------------------
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"

''...trying WriteFile
Response.WriteFile("~/xml/result.pdf")

''...trying BinaryWrite
Response.BinaryWrite(fPDF)

''...trying OutputStream
Response.OutputStream.Write(fPDF, 0, fPDF.Length)
Response.Flush()
Response.Close()
''--------------------------------------------

Is it possibly because the requested page has the *.aspx extension? If
it
is, is there a way around this?




这篇关于WriteFile,BinaryWrite,OutputStream ......都无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆