Click here to Skip to main content
16,021,209 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai
How to retrive a pdf file from database when clicking scrolling news link?

XML
string strsql = "select * from Event";
        string strscrolling = "";
        HtmlTableCell cellscrolling = new HtmlTableCell();
        HtmlTableCell rowScrolling = new HtmlTableCell();
        SqlCommand mycomd = new SqlCommand(strsql, conn);
        SqlDataReader sqlrdr;
        try
        {
            conn.Open();
            sqlrdr = mycomd.ExecuteReader();
            strscrolling="<Marquee onmouseover='this.stop();' onmouseout='this.start();' direction='up'>";
            while (sqlrdr.Read())
            {
                strscrolling = strscrolling + "<a href='#' OnClick=" + "javascript:window.open(target='_blank'?Id=" + sqlrdr.GetValue(0) + "','Ttle','width=400,height=400;toolbar=no;');" + "><font face='verdana' size='2' color='#ffffff'>" + sqlrdr.GetValue(1) + "</a>&nbsp;&nbsp;" + sqlrdr.GetValue(2).ToString() + "</font><br><br>";
            }
            strscrolling=strscrolling+"</Marquee>";
            sqlrdr.Close();
            cellscrolling.InnerHtml=strscrolling;
            //rowScrolling.Cells.Add(cellscrolling);
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);

        }
        finally{
            conn.Close();
        }
            }
Posted
Updated 22-Sep-12 23:29pm
v2

If you have the binary data in the database you can use an HttpHandler to spit out the data using something along the lines of:
C#
public void ProcessRequest(HttpContext context)
{
    int id;
    if(Int32.TryParse(context.Request.QueryString["id"], out id))
    {
        var data = GetPDFFromDB(id);
        context.Response.Buffer = true;
        context.Response.ContentType = "application/pdf";
        context.Response.AddHeader("Content-Length", data.Length.ToString());
        context.Response.WriteBinary(data);
    }
    else
    {
        context.Response.WriteLine("Invalid id");
    }
}


See the documentation for more details: http://msdn.microsoft.com/en-us/library/system.web.httpresponse(v=vs.100).aspx[^]

Hope this helped :-)
 
Share this answer
 
Looks like you already are opening a new window on click of a text field (PDF name link). Just open the PDF in Page_Load of new window. Looks like you already have all the needed details for picking up right PDF in querystring.
 
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