Click here to Skip to main content
15,896,497 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have one image control in my application i want to display the image , instead of displaying pdf or jpg images i want to see the content of the page in image control

What I have tried:

<asp:Image ID="displayImage" Style="padding: 0px" Height="86" Width="84" ImageAlign="Middle" ImageUrl='<%# "../Handlers/ImageHandlerNew.ashx?DocumentId=" + Eval("BeneficiaryDocumentId") + "&IsThumbnail=true"%>' runat="server" />

imagehanlder.ashx


public void ProcessRequest(HttpContext context)
{
string documentID = context.Request.QueryString["DocumentId"].ToString();
string isThumbnail = context.Request.QueryString["IsThumbnail"].ToString();
BizBeneficiaryDocuments bizBeneficiaryDocuments = new BizBeneficiaryDocuments();
DataTable data = bizBeneficiaryDocuments.GetImageDataByID(documentID.ToInt32());
if (data.Rows.Count > 0)
{
DataRow dr = data.Rows[0];
if (isThumbnail.Equals("true"))
{
byte[] byteData;
if (dr[0].ToString().Contains("pdf"))
{
byteData = File.ReadAllBytes(HttpContext.Current.Server.MapPath("../img/pdf_128.png"));
}
else if (dr[0].ToString().Contains("application/vnd.openxmlformats"))
{
byteData = File.ReadAllBytes(HttpContext.Current.Server.MapPath("../img/ppt_128.png"));
}
else if (dr[0].ToString().Contains("ms-word"))
{
byteData = File.ReadAllBytes(HttpContext.Current.Server.MapPath("../img/word_128.png"));
}
else if (dr[0].ToString().Contains("image"))
{
byteData = File.ReadAllBytes(HttpContext.Current.Server.MapPath("../img/images.jpg"));
}
else
{
byteData = (byte[])dr[1];
}
context.Response.BinaryWrite(byteData.MakeThumbnail(64, 64));// MakeThumbnail(byteData, 64, 64));
}
else
{
context.Response.BinaryWrite((byte[])dr[1]);
}
context.Response.ContentType = dr[0].ToString();
}
context.Response.Flush();
context.Response.End();
}
Posted
Updated 29-Jan-18 19:19pm
Comments
[no name] 30-Jan-18 1:14am    
Do you want to show contents of a PDF file or you want to show some HTML page inside a image control?

1 solution

For showing a PDF file content inside an image control please look below example.

Displaying the Contents of a PDF File in an ASP.NET Application using GhostScript[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900