Re: Complete Newbie

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I will try this. Thank you for your help. Like I said, I am trying to
teach myself and will be looking for help frequently I am sure.

Thanks again

"Oenone" <oenone@xxxxxxxxxxx> wrote in message
news:u%23PJGCGGHHA.924@xxxxxxxxxxxxxxxxxxxxxxx
encino1030@xxxxxxxxx wrote:
I want to creat a form with various buttons. each button will load a
file on the same CD that the exe file is on.
nothing fancy, just launch some .doc, .xls and PDF files.

This should be fairly straightforward...

Create your form and add the buttons you want to use to launch the files.
Lay them all out and set their properties however you want.

Double-click one of the buttons to open up its Click event handled in the
code editor. Paste in the following code:

\\\
Dim filename As String

'Get the drive the running EXE was launched from
filename = IO.Path.GetPathRoot(Assembly.GetExecutingAssembly.Location)

'Append the name of the file to open
filename &= "Test.doc"

'Launch the file
Process.Start(filename)

///

This code first gets the root path of the running executable. If it's
running from the CD-ROM drive, this will be the letter of that drive. It
is returned in the format "X:\".

The filename to be opened ("Test.doc" in this case) is then appended.
Change this for each button to be whatever you need. Include
subdirectories too if required (e.g., "MyFolder/MyFile.pdf").

Finally, Process.Start() is used to instruct Windows to open the file in
the appropriate file viewer. If no viewer is registered for the file type,
this will throw an exception so be prepared to catch it in this case. With
a little more work you can prompt the user to select which viewer to use
under these circumstances -- take a look at the documentation for the
System.Diagnostics.Process class for more info, and in particular the
ErrorDialog property.

HTH,

--

(O)enone



.


Quantcast