Link to home
Start Free TrialLog in
Avatar of ybt
ybt

asked on

PDF document on a web page

In ASP.NET C# I create a possibility to open pdf file


in cs file:
protected void bttnpdf_Click(object sender, EventArgs e)
        {

            WebClient User = new WebClient();

            Byte[] FileBuffer = User.DownloadData("\\\\lsmfs1\\726984\\2016\\726984.pdf");

            if (FileBuffer != null)
            {

                Response.ContentType = "application/pdf";

                Response.AddHeader("content-length", FileBuffer.Length.ToString());

                Response.BinaryWrite(FileBuffer);

            }

        }

in aspx:
<asp:Button ID="bttnpdf" runat="server" Text="Click for open PDF" Font-Bold="True" OnClick="bttnpdf_Click" />

PDF document takes whole page to open, I do not find an option to go back, only close browser,
can I open this document in some container in the page or create some "BACK" functionality?
Avatar of JS List
JS List
Flag of United States of America image

Can you open it in an IFrame?  I do this all the time.  The page containing the IFrame can have a back button.  Use javascript to go back 1 page  in history.
Avatar of Robberbaron (robr)
i pass the id of the pdf document to an ashx handler via a link button., tht way you can tell the the link to open in new tab.

dont have access to my code at the moment but the ashx is very similar to your current code. ( i pass an id#, where you could pass the path to file, while it is oart of url, the ashx displays the file so the path is not visible)
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ybt
ybt

ASKER

Thank you