[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

Open .pdf file through the browser

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
sticar
Asked:
sticar
  • 6
  • 2
  • 2
1 Solution
 
DotNetLover_BaanCommented:
are you stuck some where ? this code is working fine, it is opening the file...  What is your exact problem ?
-Baan
0
 
sticarAuthor Commented:
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
 
ihenryCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Thanks anyway!
0
 
sticarAuthor Commented:
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
 
DotNetLover_BaanCommented:
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
 
sticarAuthor Commented:
? 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
 
ihenryCommented:
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
 
sticarAuthor Commented:
That is PERFECT!!  I used dropdownlist1
Thank you!!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now