locked
Render images from Access Database stored as OLE Objects RRS feed

  • Question

  • User168885582 posted
    Hello everyone, I can't get this handler to render anything more than an image placeholder with a red X in it. What am I doing wrong? I have a SQL Server version working perfectly, but this OLE version isn't rendering at all. The images are stored as OLE Objects (long binary), and I'm using C#. Anyone have any ideas? Below is my code so far... 
    public void ProcessRequest (HttpContext context)
    {
        OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings[2].ToString());
        con.Open();
        OleDbCommand cmd = new OleDbCommand("select MIMEType, DocFile from tbl_Documents where pk_DocID = " + HttpContext.Current.Request.QueryString[0], con);
        OleDbDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.CloseConnection);
        context.Response.Clear();
       while (rdr.Read())
        {
            context.Response.ContentType = rdr[0].ToString();
           byte[] bytes = (byte[])rdr[1];
            context.Response.BinaryWrite(bytes);
            context.Response.Flush();
            bytes = null;
        }
    }
    TIA,
    Brandon
    Friday, December 22, 2006 7:11 PM

Answers

  • User168885582 posted

    Hi,

    Actually it was the way I was saving the data in to the db that was causing the problem, but everything is cool now and it works like a charm. I didn't have to change any of my ashx handler code.

    Brandon

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 1, 2007 10:52 PM

All replies

  • User-212531434 posted
    Have you set the Content-Disposition? Something like: Response.AddHeader("Content-Disposition", "filename=\"" + Server.HtmlEncode(Filename) + "\""); If you are still having trouble the best thing to use is something that will show you the http headers and compare with a direct image link.
    Monday, January 1, 2007 7:03 PM
  • User168885582 posted

    Hi,

    Actually it was the way I was saving the data in to the db that was causing the problem, but everything is cool now and it works like a charm. I didn't have to change any of my ashx handler code.

    Brandon

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 1, 2007 10:52 PM