473,382 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Opening a PDF document

I'm currently using System.Diagnostics.Process.Start("..\Documents\sam ple.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.
Feb 12 '10 #1

✓ answered by sashi

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private fdlg As OpenFileDialog = New OpenFileDialog()
  3.  fdlg.Title = "PDF Document"
  4.  fdlg.InitialDirectory = "c:\"
  5.  fdlg.Filter = "PDF File|*.pdf"
  6.  fdlg.FilterIndex = 2
  7.  fdlg.RestoreDirectory = True
  8.  
  9. If fdlg.ShowDialog() = DialogResult.OK Then
  10. textBox1.Text = fdlg.FileName
  11. End If 
  12.  

5 2077
lotus18
866 512MB
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.StartupPath will solve your problem
Feb 12 '10 #2
sashi
1,754 Expert 1GB
Dim exePath as String = ""

exePath = System.Reflection.Assembly.GetExecutingAssembly.Lo cation

WebBrowser1.Navigate (exePath & "\" & "pdf_filename")
Feb 12 '10 #3
tlhintoq
3,525 Expert 2GB
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.
Feb 12 '10 #4
sashi
1,754 Expert 1GB
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.InitialDirectory = "c:\"
Private fdlg.Filter = "PDF File|*.pdf"
Private fdlg.FilterIndex = 2
Private fdlg.RestoreDirectory = True
If fdlg.ShowDialog() = DialogResult.OK Then
textBox1.Text = fdlg.FileName
End If
Feb 13 '10 #5
sashi
1,754 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private fdlg As OpenFileDialog = New OpenFileDialog()
  3.  fdlg.Title = "PDF Document"
  4.  fdlg.InitialDirectory = "c:\"
  5.  fdlg.Filter = "PDF File|*.pdf"
  6.  fdlg.FilterIndex = 2
  7.  fdlg.RestoreDirectory = True
  8.  
  9. If fdlg.ShowDialog() = DialogResult.OK Then
  10. textBox1.Text = fdlg.FileName
  11. End If 
  12.  
Feb 13 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jawahar Rajan | last post by:
All, I have a printer friendly page that is opened when a user clicks a link on my page to get the printer friendly version, How ever when they close out the printer friendly version and return to...
3
by: Display Name | last post by:
When this form's being submitted, two windows are opening instead of only one here is the function I'm using: function subForm(){ //insert form validation here //if form is valid, open a...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
2
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
5
by: Cedric | last post by:
Hi Folks, I'm wondering if someone has already succeed to open a word2000 document located on server side with javascript code executed by a web browser on client side. In fact, i make it...
0
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I am creating a webpage and opening it as a Word document. Problem is that as I create one of the questions, some of the text is not appearing in the document as it should. As I step through it, I...
0
by: aarthiraaj | last post by:
In my user screen I have view link, if I click this link it will go to servlet and open one word document. It is opening properly, but while opening the attachment it generate one dialog box like...
1
by: abhishekbrave | last post by:
The code below is opening a calendar on mouse over in the same window. I need the calendar to be opened in new window. Have to fulfill this requirement urgentely so posting the whole code here. I...
2
by: rlu | last post by:
Is there a way to print a pdf document without opening it, if user just select the pdf files in the checkbox and click a button? I tried the following two methods, but both fail. 1. open a new...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.