链接到pdf文件(asp.net) [英] link to pdf file(asp.net)
问题描述
我已使用文件上载将pdf文件保存到数据库中.现在我想从数据库中检索pdf文件,它必须链接到动态创建的链接按钮.因此,对于每个链接按钮,我都有一个链接到它的pdf文件.-如何使用C#
i have saved the pdf file to the database using file upload . now i want to retrive the pdf file from the database and it has to be linked to the linkbuttons that are dynamically created . so for each link button i have a pdf file linked to it. - how to do this in asp.net using C#
推荐答案
首先,您必须从数据库中读取记录.
First you'd have to read the records from the database.
假设您具有以下表结构:
Let's say you have the following table structure:
Id,名称,BinaryPdfData
Id, Name, BinaryPdfData
您使用ADO.NET,Linq2SQL或任何用于选择" ID和名称的东西放入IEnumerable(例如List或DataSet).
You use ADO.NET, Linq2SQL or whatever you're using to "SELECT" Id and Name into an IEnumerable (for example a List or DataSet).
然后将其绑定到ASP Repeater,其中ItemTemplate包含一个LinkButton,而Click事件背后的代码将然后将您重定向到某个下载页面,例如"downloadpdf.aspx?id = {0}"
Then you bind that to an ASP Repeater where the ItemTemplate contains a LinkButton and the code behind for the Click event would then redirect you to some download page for example "downloadpdf.aspx?id={0}"
{0}是记录的ID.
Where {0} is the Id of the record.
download.aspx页从数据库中读取指定的记录并将二进制pdf数据放入缓冲区数组.
The download.aspx page reads the specified record from the database and puts the binary pdf data in a buffer array.
接下来,您必须设置内容类型等...
Next you'll have to set the content type etc...
我没有时间建立一个很好的例子,但是您可能需要这个:
I don't have time to build a good example, but you'll probably need this:
Response.Clear()
//set the content type to PDF
Response.ContentType = "application/pdf"
//add content type header
Response.AddHeader("Content-Type", "application/pdf")
//set the content disposition
Response.AddHeader("Content-Disposition", "inline;filename=helloworld.pdf")
//write the buffer with pdf file to the output
Response.BinaryWrite(Buffer)
Response.End()
这篇关于链接到pdf文件(asp.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!