Opening a PDF document

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bjm3819
    New Member
    • Feb 2010
    • 1

    Opening a PDF document

    I'm currently using System.Diagnost ics.Process.Sta rt("..\Document s\sample.pdf") to open the document. It works great but in my program when I open up a document using the OpenDialog control it will break something.
    After opening up a file using the OpenDialog control I try to open up the PDF but then the file cannot be found. I think current path changes... and is no longer in the directory I need it to be in.

    How do I get VB to tell me its current directory or even tell me the path of the install program so I can tell it where to go to find the document?

    The big issue is that I deploy this program to many users so they may install it in different areas so I cannot use the same file location such as C:\ProgramFiles \PDF_Docs\myPdf .pdf as the path.

    I have a folder for documents in side my vb project that holds the document.
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    How do I get VB to tell me its current directory or even tell me the path of the install program so I can tell it where to go to find the document?
    I guess Application.Sta rtupPath will solve your problem

    Comment

    • sashi
      Recognized Expert Top Contributor
      • Jun 2006
      • 1749

      #3
      Dim exePath as String = ""

      exePath = System.Reflecti on.Assembly.Get ExecutingAssemb ly.Location

      WebBrowser1.Nav igate (exePath & "\" & "pdf_filena me")

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I think you guys are getting sidetracked with this.
        It works great but in my program when I open up a document using the OpenDialog control it will break something.
        It shouldn't matter what your exe path is if you are getting the PDF path from the OpenFileDialog. It returns an absolute path to the file, not relative to your application.

        Are you in some way modifying the path after you get it from the dialog? Perhaps you should post the relevant code.

        Comment

        • sashi
          Recognized Expert Top Contributor
          • Jun 2006
          • 1749

          #5
          Hi there,

          Try the below attached code segment. It works fine for me. Hope it does for you too :)

          Private fdlg As OpenFileDialog = New OpenFileDialog( )
          Private fdlg.Title = "PDF Document"
          Private fdlg.InitialDir ectory = "c:\"
          Private fdlg.Filter = "PDF File|*.pdf"
          Private fdlg.FilterInde x = 2
          Private fdlg.RestoreDir ectory = True
          If fdlg.ShowDialog () = DialogResult.OK Then
          textBox1.Text = fdlg.FileName
          End If

          Comment

          • sashi
            Recognized Expert Top Contributor
            • Jun 2006
            • 1749

            #6
            Code:
            Private fdlg As OpenFileDialog = New OpenFileDialog()
             fdlg.Title = "PDF Document"
             fdlg.InitialDirectory = "c:\"
             fdlg.Filter = "PDF File|*.pdf"
             fdlg.FilterIndex = 2
             fdlg.RestoreDirectory = True
            
            If fdlg.ShowDialog() = DialogResult.OK Then
            textBox1.Text = fdlg.FileName
            End If

            Comment

            Working...