Solved

Open .pdf file through the browser

Posted on 2004-08-21
10
312 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
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net 2 43
vb.net checkbox 7 47
Call windows 10 virtual keyboard from windows forms app 2 36
How to open form using item in Listbox. 8 21
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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