您好我想将PDF文件或.DOC或保存在我的数据库中的图像显示在我的ASP.net页面中。 我尝试了这个代码,但没有成功。有什么想法我该怎么办?
<object type="application/pdf" data="~/Protected/docs/CV_Zied_JOUINI.pdf" width="400" height="300">
<param name="movie" value="~/Protected/docs/CV_Zied_JOUINI.pdf" />
<img src="~/Protected/docs/CV_Zied_JOUINI.pdf" alt="" width="200" height="100" />
答案 0 :(得分:1)
我想显示PDF文件或.DOC或图像保存在我的数据库中 进入我的ASP.net页面
如果文件保存在数据库中,则通常采用二进制格式。
如果是这样,您需要文件处理程序才能将这些二进制数据显示回客户端 浏览器。
例如,
public class FileHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string id = context.Request.QueryString["id"];
// Let say you get the file data from database based on id
// ...
var fileData = new byte[] { ... };
string fileName = "PDF_FILENAME.pdf";
context.Response.Clear();
// Need to return appropriate ContentType for different type of file.
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition",
"attachment; filename=" + fileName);
context.Response.AddHeader("Content-Length", fileData.Length.ToString());
context.Response.Write(fileData);
context.Response.End();
}
public bool IsReusable
{
get { return false; }
}
}
<a href="/FileHandler.ashx?id=1">My File</a>
答案 1 :(得分:0)
如果没有看到您的代码,您可以考虑将object
标记放在div
内。我不相信您需要PDF的param
和img
标签。试试这个,
<div> <object data="~/Protected/docs/CV_Zied_JOUINI.pdf" type="application/pdf" width="300" height="200"> alt : <a href="test.pdf">test.pdf</a> </object> </div>
答案 2 :(得分:0)
假设您的意思是关系数据库而不仅仅是文件系统(您的问题不明确)。
Response.ContentType
为其返回的文件将其响应标头设置为适当的内容类型,并使用Response.BinaryWrite()
将文件写入响应。<object>
或<img>
元素中的路径应指向通用处理程序,确保使用查询字符串参数传递所请求文件的标识,例如:{{1其中fileretriever.ashx?document=XXX-XXX
是文件的标识。答案 3 :(得分:0)
谢谢大家。我使用了这段代码和它的工作
<iframe src="/Protected/docs/CV_Zied_JOUINI.pdf" width="1320px" height="1500px"></iframe>
谢谢你:)