Search code examples
asp.netvisual-studio-2010rdlcreport-viewer2010

RDLC Report Viewer Control - How to open images in another window/tab


I have images in the database (SQlServer 2008 R2) in a varbinary column. My report is developed in ASP.net 3.5 in Visual Studio 2010. On my report in a table, I use an Image, set the MIME type to image/jpeg, image source as Database & the image is displayed correctly in the report. Everything works!! Now my issue is that, I would like to add a hyperlink to that image so that when the user clicks on the image it opens in another window/tab in its original format. This will help the user to get a closer look at the image. I tried to add Hyperlink - Go to URL - Expression

="http://localhost:49170/MtkMobileDeposit_FailedTransaction/Account/ReportByUserName.aspx?BackImageOriginal=" & Fields!BackImageOriginal.Value

But I cannot get it to display only the image. Instead it displays the entire report in a new tab. How do I first get the URL for the images to work ? Please help.

Thanks, sdd


Solution

  • Your best bet is to use a httphandler to process your request.

    Create an ImageHandler.ashx that will take in the record id. Then you can get the image's byte array and out put it to the screen.

    Your new URL will look like

    "/ImageHandler.ashx?Record_ID=" & Fields!RecordId.Value

    public class ImageHandler : IHttpHandler
    {
    
        public int Record_ID
        {
            get { return Convert.ToInt32(HttpContext.Current.Request.QueryString["Record_ID"]); }
    
        }
    
        public void ProcessRequest(HttpContext context)
        {
            // get image from database into a byte array
            Component.ImageController objImageController = new Component.ImageController();
            Component.ImageInfo objImageInfo = objImageController.getImage(Record_ID);
            byte[] byteArray = objImageInfo.photo;
    
            // output it to the screen
            context.Response.Clear();
            context.Response.ContentType = "image/jpeg";
            context.Response.BinaryWrite(byteArray);
    
            context.ApplicationInstance.CompleteRequest();
    
        }
    
    
    
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }