Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Open a PDF file

Open a PDF file

Scheduled Pinned Locked Moved ASP.NET
csharpvisual-studiosysadmin
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rudemusik
    wrote on last edited by
    #1

    Hello All! I'm working in VS 2005/VB.NET. There seems to be alot of ways to this. I'm just looking to open up a pdf file from a server. I don't have to modify or save it. I just need to view it in the web page. Can somebody show me or point me to a quick of doing this. Thanks! Rudy

    S 1 Reply Last reply
    0
    • R rudemusik

      Hello All! I'm working in VS 2005/VB.NET. There seems to be alot of ways to this. I'm just looking to open up a pdf file from a server. I don't have to modify or save it. I just need to view it in the web page. Can somebody show me or point me to a quick of doing this. Thanks! Rudy

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      if you are doing it server side code use response.redirect(pathWithFilename.pdf) and on clicent you can just give a link/button and open the pdf file like a href='http:\\url\file.pdf'

      -----

      R 1 Reply Last reply
      0
      • S SABhatti

        if you are doing it server side code use response.redirect(pathWithFilename.pdf) and on clicent you can just give a link/button and open the pdf file like a href='http:\\url\file.pdf'

        -----

        R Offline
        R Offline
        rudemusik
        wrote on last edited by
        #3

        Hello Sabhatti! Thank you for the quick response. That worked great, but I didn't realize it would open adobe. Is there a way to open a pdf file, while still in the webpage? Thanks! Rudy

        A 1 Reply Last reply
        0
        • R rudemusik

          Hello Sabhatti! Thank you for the quick response. That worked great, but I didn't realize it would open adobe. Is there a way to open a pdf file, while still in the webpage? Thanks! Rudy

          A Offline
          A Offline
          A R Bhagirathi
          wrote on last edited by
          #4

          hi you can try this : convert the file into byte array,set the Response.ContentType to application/pdf and do a binary write Sample code: string filePath=Request.MapPath("a.pdf"); System.IO.FileInfo ofile=new FileInfo(filePath); System.IO.FileStream fs = ofile.OpenRead(); int filelen=(int)fs.Length; byte[] b=new byte[filelen]; fs.Read(b,0,filelen); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType="application/pdf"; Response.BinaryWrite(b); Response.End(); Response.Flush();

          J R 2 Replies Last reply
          0
          • A A R Bhagirathi

            hi you can try this : convert the file into byte array,set the Response.ContentType to application/pdf and do a binary write Sample code: string filePath=Request.MapPath("a.pdf"); System.IO.FileInfo ofile=new FileInfo(filePath); System.IO.FileStream fs = ofile.OpenRead(); int filelen=(int)fs.Length; byte[] b=new byte[filelen]; fs.Read(b,0,filelen); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType="application/pdf"; Response.BinaryWrite(b); Response.End(); Response.Flush();

            J Offline
            J Offline
            Jay_se
            wrote on last edited by
            #5

            Hi, What is the advantage of this way over SABhatti's statement? Please explain me.

            Regards, Jay :)

            1 Reply Last reply
            0
            • A A R Bhagirathi

              hi you can try this : convert the file into byte array,set the Response.ContentType to application/pdf and do a binary write Sample code: string filePath=Request.MapPath("a.pdf"); System.IO.FileInfo ofile=new FileInfo(filePath); System.IO.FileStream fs = ofile.OpenRead(); int filelen=(int)fs.Length; byte[] b=new byte[filelen]; fs.Read(b,0,filelen); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType="application/pdf"; Response.BinaryWrite(b); Response.End(); Response.Flush();

              R Offline
              R Offline
              rudemusik
              wrote on last edited by
              #6

              Hi A.R.! What do you mean by converting the file into a byte array? Thanks! Rudy

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups