Reputation: 145
hi i want to display a PDF file or .DOC or an image saved in my Data Base into my ASP.net page. i tryed this code but without sucess. have any one an idea how can i do it ?
<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" />
Upvotes: 2
Views: 5187
Reputation: 145
Thank you for all. I used this code and it's work
<iframe src="/Protected/docs/CV_Zied_JOUINI.pdf" width="1320px" height="1500px"></iframe>
thank you :)
Upvotes: 0
Reputation: 32694
Assuming you meant a relational database instead of just the file system (your question was ambiguous).
Response.ContentType
for the file it is returning, and write the file to the response using Response.BinaryWrite()
.<object>
or <img>
elements in the HTML should point to the generic handler, making sure to pass the identity of the requested file with a query string parameter, ex: fileretriever.ashx?document=XXX-XXX
where XXX-XXX
is the identify of the file.Upvotes: 0
Reputation: 62260
i want to display a PDF file or .DOC or an image saved in my Data Base into my ASP.net page
If a file is saved in Database, it is normally in Binary format.
If so, you need a File Handler in order to display those Binary Data back to client browser.
For example,
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>
Upvotes: 1
Reputation: 178
Without seeing your code in action, you might consider placing the object
tag inside a div
. I'm not convinced you need the param
and img
tags for a PDF though. Try this,
<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>
Upvotes: 0