Need Help with Shell

  • Thread starter Thread starter Jack Russell
  • Start date Start date
J

Jack Russell

Why doesn't the following code run acrobat?
It throws a file not found exception

Thanks

Dim s As String = sgAppPath + "TCW3Help.pdf"
Try
If Not File.Exists(s) Then
MsgBox("Cannot find " + s, MsgBoxStyle.Exclamation)
Else
s = """" + s + """"
Shell(s)
End If
Catch ex As FileNotFoundException
MsgBox("Unable to open Help file " + s + " check that
Acrobat is installed", MsgBoxStyle.Exclamation)
Catch ex As Exception
ReportBug(ex, "Trying to open help file " + s)
End Try
 
Try this:

Dim s As String = Application.StartupPath & "\TCW3Help.pdf"
Try
If Not IO.File.Exists(s) Then
MessageBox.Show(String.Format("Cannot find {0}", s),
Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
Microsoft.VisualBasic.Shell(s, AppWinStyle.NormalFocus)
End If
Catch ex As IO.FileNotFoundException
MessageBox.Show(String.Format("Unable to open Help file {0}.
Check that Acrobat is installed", s), Me.Text, MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Catch ex As Exception
MessageBox.Show(ex, "Trying to open help file " + s)
End Try

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
 
Thanks but still get the same thing, exception on the shell command.

Any other ideas?
 
I changed the filename to one on my system & it worked for me. Just play
around with the Try Catch End Try block.

Sorry, but I don't have the time to do anything else for the next 3-4 hours,
but later if you don't have a solution then I'll re-write it for you.

Crouchie1998
BA (HONS) MCP MCSE
 
Jack,

Did you try it already with Process.Start(filenme)
(Needs a reference to be set).

Pdf, should of couse start when you click in explorer on that, otherwise you
have to name the program in this method as well.

In addition when you try something, set than first the hardcoded path in it,
that makes finding an error much easier.

I hope this helps,

Cor
 
Crouchie1998 said:
Dim s As String = Application.StartupPath & "\TCW3Help.pdf"

=> 'System.IO.Path.Combine'. Otherwise the path will contain two
backslashes if the application is installed to a drive's root directory.
 
Thanks, still no joy but took Cors suggestion and used process.start -
no problems.
One thing I can say for .net, there seem to a thousand ways of doing
anything and one eventually works!
 
I just recoded your solution because that's the way you wanted to code it.
Process.Start is an easier way, I agree

Crouchie1998
BA (HONS) MCP MCSE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top