Solved

Open .pdf file through the browser

Posted on 2004-08-21
10
285 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
  • 6
  • 2
  • 2
10 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:sticar
Comment Utility
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
Comment Utility
I just upgraded my Adobe Reader to 6.0.2 from 5.0 and it opens just fine now... ugh.....

Thanks anyway!
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:sticar
Comment Utility
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
Comment Utility
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
Comment Utility
? 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
Comment Utility
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
Comment Utility
That is PERFECT!!  I used dropdownlist1
Thank you!!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now