Solved

Open .pdf file through the browser

Posted on 2004-08-21
10
332 Views
Last Modified: 2010-05-18
I went through this site, step by step, and all it does it clear the screen and put a small image icon in the top left side of the screen.  The one that shows if there is a missing image.  I have adobe acrobat reader, and opened the file fine.  I didn't see any "Adobe Acrobat" items in the references list to be added... (if that is the issue)?

http://support.microsoft.com/default.aspx?scid=kb;en-us;307603&Product=vbNET

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Response.ContentType = "Application/pdf"
        'Get the physical path to the file.
        Dim FilePath As String = MapPath("readme.pdf")
        'Write the file directly to the HTTP output stream.
        Response.WriteFile(FilePath)
        Response.End()
    End Sub

Any clue?  Thanks!
0
Comment
Question by:sticar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11861884
are you stuck some where ? this code is working fine, it is opening the file...  What is your exact problem ?
-Baan
0
 

Author Comment

by:sticar
ID: 11862426
Strange...  all it does for me is put a little square at the top left, but the link stays the same (which it should).

I don't have to include any resources do I?
0
 
LVL 20

Expert Comment

by:ihenry
ID: 11862942
are you sure the FilePath variable is pointing to the correct path or the physical file is in the folder?
use File.Exists( FilePath ) method to determine whether the file is there.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sticar
ID: 11863769
I went through debugger and it has the full correct path.  It acts like it doesn't see it though.  This may not matter, but the icon for "readme.pdf" is a generic one, not the Adobe Acrobat one, but it will open up in Adobe when I right-click and open it.
0
 

Author Comment

by:sticar
ID: 11863801
I just upgraded my Adobe Reader to 6.0.2 from 5.0 and it opens just fine now... ugh.....

Thanks anyway!
0
 

Author Comment

by:sticar
ID: 11863855
If you know how I can modify it to open in a separate window, I'll give you the points.

Thanks for all your help!
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11864649
Hi there,
say you are clicking on a link to open that. In the Page_Load event of the newly opened window, you have the working code. Now go to the parent page (where the link is) and use Javascript:window.open('MyNewPage.aspx')..  just like I showed for the Camtasia Files.
0
 

Author Comment

by:sticar
ID: 11865504
? I'm working with a combo box actually so when I change the item it immediately opens the link window.

        If strExt = ".pdf" Then
            Response.ContentType = "Application/pdf"
            'Get the physical path to the file.
            Dim FilePath As String = MapPath(dir + filename)
            'Write the file directly to the HTTP output stream.
            Response.WriteFile(FilePath)                                        'can I put javascript in here somehow?
            Response.End()
        End If
0
 
LVL 20

Accepted Solution

by:
ihenry earned 250 total points
ID: 11868665
Try this quick sample, the code is quite self explanatory.

=-=-=- webform3.aspx =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="webVB.WebForm3"%>
<HTML>
      <HEAD>
            <title></title>
            <script language="javascript">
            <!--
            function OpenFile( sel, useCodebehind )
            {
                  if (sel.selectedIndex == 0) return;

                  //var text = sel.options[sel.selectedIndex].text
                  var file = sel.options[sel.selectedIndex].value
                  if ( !useCodebehind )
                  {
                        //window.open(file,'newWin','width=400,height=400,toolbar=1,menubar=1,location=1,resizable=1')
                        window.open(file,'newWin','width=400,height=400,resizable=1')
                  }
                  else
                  {
                        //window.open('WebForm4.aspx?f=' + file,'newWin','width=400,height=400,toolbar=1,menubar=1,location=1,resizable=1')
                        window.open('WebForm4.aspx?f=' + file,'newWin','width=400,height=400,resizable=1')
                  }
            }
            // -->
            </script>
      </HEAD>
      <body>
            <form id="Form1" method="post" runat="server">
                  <p>
                        <h4>Open a file directly from JavaScript</h4>
                        <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
                  </p>
                  <p>
                        <h4>Open a file from code behind</h4>
                        <asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
                  </p>
            </form>
      </body>
</HTML>
=-=-=- webform3.aspx.vb =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-Public Class WebForm3
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not Page.IsPostBack Then

            DropDownList1.Items.Add(New ListItem("-- Select a file to open --", "value0"))
            DropDownList1.Items.Add(New ListItem("DateTime Structure FAQ", "docs/datetimefaq.pdf"))
            DropDownList1.Items.Add(New ListItem("How to Solve Debugger Problems", "docs/howtosolvedebuggerproblems.pdf"))
            DropDownList1.Items.Add(New ListItem("Journal on Wild Web West", "docs/journal1_web.pdf"))
            DropDownList1.Items.Add(New ListItem("Design of a Persistence Layer White Paper", "docs/persistenceLayer.pdf"))

            DropDownList2.Items.Add(New ListItem("-- Select a file to open --", "value0"))
            DropDownList2.Items.Add(New ListItem("DateTime Structure FAQ", "datetimefaq.pdf"))
            DropDownList2.Items.Add(New ListItem("How to Solve Debugger Problems", "howtosolvedebuggerproblems.pdf"))
            DropDownList2.Items.Add(New ListItem("Journal on Wild Web West", "journal1_web.pdf"))
            DropDownList2.Items.Add(New ListItem("Design of a Persistence Layer White Paper", "persistenceLayer.pdf"))

        End If

        DropDownList1.Attributes.Add("onchange", "JavaScript:OpenFile( this, false )")
        DropDownList2.Attributes.Add("onchange", "JavaScript:OpenFile( this, true )")
    End Sub

End Class
=-=-=- webform4.aspx =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm4.aspx.vb" Inherits="webVB.WebForm4"%>
<HTML>
      <HEAD>
            <title></title>
      </HEAD>
      <body>
            <form id="Form1" method="post" runat="server">
                  &nbsp;
            </form>
      </body>
</HTML>
=-=-=- webform4.aspx.vb =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-Public Class WebForm4
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
            If Not IsNothing(Request.QueryString("f")) Then
                Dim f As String = Request.QueryString("f")
                Dim filePath As String = MapPath(f)
                Response.ContentType = "application/pdf"
                Response.WriteFile(filePath)
                Response.End()
            End If
        End If
    End Sub

End Class


Hope this helps
0
 

Author Comment

by:sticar
ID: 11877261
That is PERFECT!!  I used dropdownlist1
Thank you!!!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question