从数据库中读取image字段内容的一个问题!

jxlucy 2004-08-19 10:27:15
在数据库表中的image字段中,存了图片以及PDF
现在要在浏览器中显示字段的内容,代码如下:
<%
string sql="select personimage,personimagetype from person where personid=1"
sqlconnection connection=new sqlconnection("server=(local);database=test;uid=gqy;pwd=gqy")
sqlcommand command=new sqlcommand(sql,connection)
connection.open()
sqldatareader dr=command.executereader()
if(dr.read())
{
response.contenttype=dr["personimagetype"].tostring()
response.binarywrite((byte[]) dr["personimage"])
}
connection.close()
%>
现在的问题是:浏览图片的时候没什么问题,但是浏览PDF的时候不能像浏览图片一样直接显示,而是会弹出一对话框,让选择是打开还是保存,选择打开后,自动启动PDF阅读器打开PDF文档。我希望实现这样的目标:当浏览PDF的时候,能直接在IE里显示PDF文档(像现在网上很多是这样的)!
谢谢!
...全文
141 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
jasonlee0927 2004-08-26
  • 打赏
  • 举报
回复
response.write("<script language='javascript'>window.open('abc.pdf','','')</script>")妳把abc.pdf修改為妳的變量名看看!
jxlucy 2004-08-26
  • 打赏
  • 举报
回复
各路高手帮帮忙,看看~
yingshis 2004-08-20
  • 打赏
  • 举报
回复
up
jxlucy 2004-08-20
  • 打赏
  • 举报
回复
关键是代码要如何写!
lang11zi 2004-08-20
  • 打赏
  • 举报
回复
qiang
darren_zhu_NZ 2004-08-20
  • 打赏
  • 举报
回复
Content-Disposition用来说明Response的内容是独立的附件还是inline
Content-Length定义Http Response的内容的长度

Two common ways of presenting multipart electronic messages are as a
main document with a list of separate attachments, and as a single
document with the various parts expanded (displayed) inline. The
display of an attachment is generally construed to require positive
action on the part of the recipient, while inline message components
are displayed automatically when the message is viewed. A mechanism
is needed to allow the sender to transmit this sort of presentational
information to the recipient; the Content-Disposition header provides
this mechanism, allowing each component of a message to be tagged
with an indication of its desired presentation semantics.
jxlucy 2004-08-20
  • 打赏
  • 举报
回复
大家帮忙看看!
jxlucy 2004-08-19
  • 打赏
  • 举报
回复
To net_lover:
你的这段代码我怎么看不懂啊
解释解释!
jxlucy 2004-08-19
  • 打赏
  • 举报
回复
to saucer:
这段代码有点问题!
提示说Addheader没定义之类的!
另外我想问的是:ado.pdf是?
Response.Addheader("Content-Disposition", "inline; filename=ado.pdf");
Response.AddHeader("Content-Length", bs.Length.ToString());
这两语句是什么意思,谢谢
思归兄弟!
孟子E章 2004-08-19
  • 打赏
  • 举报
回复
如果是pdf,就用

<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="760" height="411" border="0">


<param name="_Version" value="65539">


<param name="_ExtentX" value="20108">


<param name="_ExtentY" value="10866">


<param name="_StockProps" value="0">


<param name="SRC" value="illustrator.pdf">


</object>
hightwise 2004-08-19
  • 打赏
  • 举报
回复
up
saucer 2004-08-19
  • 打赏
  • 举报
回复
check response.contenttype = "application/pdf", did you set the proper content type? does your client have Adobe Acrobat Reader installed?

Response.Clear();
Response.ContentType=dr["personimagetype"].Tostring();
Response.Addheader("Content-Disposition", "inline; filename=ado.pdf");
byte[] bs = (byte[]) dr["personimage"];
Response.AddHeader("Content-Length", bs.Length.ToString());
Response.BinaryWrite(bs);
Response.End();

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧