Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 17th, 2013, 11:57 AM
Authorized User
Points: 406, Level: 7
Points: 406, Level: 7 Points: 406, Level: 7 Points: 406, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: Florida
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default Files Locations

I need to reference a PDF file in my program don't know where to put it so that the compiled and distributed program knows where to find it on a user's machine.
I have searched the book and other sources but ca't find an answer to this and related file location questions,
Reply With Quote
  #2 (permalink)  
Old January 17th, 2013, 12:51 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Probably the easiest thing to do is distribute the PDF in the same directory as the executable and then have the executable just look locally with no path information in the file name. It should be able to find it if the program hasn't changed its local directory.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #3 (permalink)  
Old January 19th, 2013, 05:09 PM
Authorized User
Points: 406, Level: 7
Points: 406, Level: 7 Points: 406, Level: 7 Points: 406, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: Florida
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default Files Locations

Thanks, Rod, for the response.

I'm still having a problem viewing the PDF. I put the PDF in each folder in the project one at a time and tried to run, none worked.

I'm still in the design phase and want to make sure that this PDF is available at run time, but just don't know where to put it.

I am at a loss as to how to insure that thedocument is available.

Milt
Reply With Quote
  #4 (permalink)  
Old January 19th, 2013, 06:21 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

How are you looking for it? Are you using File.Exists to look for it? Or are you just trying to execute it to make it display?
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #5 (permalink)  
Old January 20th, 2013, 10:28 AM
Authorized User
Points: 406, Level: 7
Points: 406, Level: 7 Points: 406, Level: 7 Points: 406, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: Florida
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default File Locations

I execute the program and then click the button with the code:

Private Sub mnuHelpGettingHelp_Click(sender As System.Object, e As System.EventArgs) Handles mnuHelpGettingHelp.Click
System.Diagnostics.Process.Start("Operations Guide.pdf")
End Sub

Thanks,again, for trying to help an old, retired amateur programmer.

Milt
Reply With Quote
  #6 (permalink)  
Old January 20th, 2013, 07:29 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hmm...

Try this. Open the Project menu, select Add Existing Item, and add the PDF file to the project. In the Properties window, click on the file and then set its "Copy to Output Directory" property to "Copy if newer." It should copy the PDF file into the executable directory when necessary.

That should make it work when you're running in the IDE or in the output directory, which is something like bin/Debug.

In the installation project, make sure to copy the file to where ever you put the executable.

Take a look at the installation directory and see of the file is present.

If it's there but the program can't open it, try putting a statement like the following in the program just before it tries to open the file.
MessageBox.Show("Operations Guide.pdf exists: " & _
System.IO .File.Exists("Operations Guide.pdf"))
That should tell you whether the program can find the file at all.

If that doesn't work, you could try changing the name of the file to something simple without the space like "OperationsGuide.pdf." I don't think it should be confused by the space but ...

If the file's path is too long, you may also have trouble. I doubt it would be too long (the limit is pretty big) but you could try a shorter name like "Guide.pdf."

Be sure to put a Try Catch block around the call to Process.Start and make the Catch block display the exception's message so you can see what it thinks is going wrong. Note that the system where you install the program won't be able to open the file if it doesn't have Acrobat Reader installed.

I hope that helps. Keep me posted.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #7 (permalink)  
Old January 21st, 2013, 03:04 PM
Authorized User
Points: 406, Level: 7
Points: 406, Level: 7 Points: 406, Level: 7 Points: 406, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: Florida
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default Files Locations

Rod,
I sincerely appreciate your trying to help. Here's where it stands now.
I created a project with only one form, which has one button control containing the code:
System.Diagnostics.Process.Start("OperationsGuide. pdf")

In the Solution Explorer at the project level I clicked the project, Add, Existing item and selected my desired output(the PDF form) I tried to run and got the following error:
"Unhand led exception has occurred in your application...." It gave me the option of continuing, if I did so it simply tried to go to the next line of code, which didn't exist
Reply With Quote
  #8 (permalink)  
Old January 21st, 2013, 07:00 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Did you set the file's "Copy to Output Directory" property to "Copy if newer?"

Did you look in the directory where the exe is built to make sure it got copied in there?

Can you double-click the file in there to make it open?

Finally did you put a Try Catch block around the call to Process.Start to see what error is being returned? "Unhandled exception" probably means you didn't use a Try Catch block. I think it should look something like this:

Code:
Try
    System.Diagnostics.Process.Start("OperationsGuide. pdf")
Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try
That should give you a better idea about what's going wrong.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #9 (permalink)  
Old January 21st, 2013, 07:51 PM
Authorized User
Points: 406, Level: 7
Points: 406, Level: 7 Points: 406, Level: 7 Points: 406, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Location: Florida
Posts: 88
Thanks: 4
Thanked 0 Times in 0 Posts
Default Files Locations

Rod

Sorry for the incomplete message that I sent earlier. I meant to complete it after watching the inauguration but inadvertently. sent the incomplete message.

I tried both and got the same error message. Could my problem be the method I'm using to try and publish my program. I am trying to use the "Publish" function from the Project in the Solution Explorer, which on the surface seems so simple.

since my project contains both an SQL Server database and several Crystal Reports, would i be better of building a distribution project?

Thanks again for your patience, follow-up and help.

Milt
Reply With Quote
  #10 (permalink)  
Old January 22nd, 2013, 01:28 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Did you try using File.Exists to see of the program can find the file?

I presume you tried opening the file manually on the installed system and it worked? That's about the only other thing I can think of. If Acrobat Reader isn't installed, the system won't know how to open the file.

You could try a simple installation project. I don't see why that would make a difference as long as the file is being installed in the correct location but it's worth a try.

Sorry I can't be more help.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating Excel FIles from resource Files abinashpatra ASP.NET 1.0 and 1.1 Basics 0 July 28th, 2008 02:07 AM
Cascading forms, form start locations pigparent Visual Basic 2005 Basics 3 June 27th, 2008 10:34 AM
One Location to Many Locations sudipkumar Biztalk 0 April 15th, 2005 08:13 AM
Default file locations selbybrock Excel VBA 0 March 9th, 2004 11:50 AM



All times are GMT -4. The time now is 04:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.