Sometimes Application.StartupPath doesn't always return the exact path to
the executing assembly. That is why I use this little function:
Private Function mypath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
Here is an example of using it, using your code and mine:
mports System.Reflection
Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(144, 40)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 266)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Open My File.PDF
Dim ps As New ProcessStartInfo
With ps
..FileName = mypath() & ("\Manual.pdf")' name of pdf file located in the Bin
Folder in this test app.
..UseShellExecute = True
End With
Dim p As New Process
p.StartInfo = ps
p.Start()
End Sub
Private Function mypath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
End Class
The above code works. I changed a couple of things from what you had.
james
"Chas Large" <Ch*******@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
Hi Phil,
Thanks for the speedy response.
I tried the code you suggest but when run it debugs out at
p.Start()
with the error:
--------------------------------------------------------------------------------------
An unhandled exception of type 'System.ComponentModel.Win32Exception'
occurred in system.dll
Additional information: The system cannot find the file specified
--------------------------------------------------------------------------------------
I have double checked the code and ensured the Imports is OK.
I also tried adding a backslash to the filename "\filename.pdf" but still
get the error
Any ideas?
BTW whats HTH, ?
Here's the code I used:
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem4.Click
'Open My File.PDF
Dim ps As New ProcessStartInfo
With ps
.FileName = SI.Path.Combine(Application.StartupPath, "\My
File.pdf")
.UseShellExecute = True
End With
Dim p As New Process
p.StartInfo = ps
p.Start()
End Sub
--
Cheers
Chas
***************
* Spectrum is Green *
***************
"Phill W." wrote:
"Chas Large" <Ch*******@discussions.microsoft.com> wrote in message
news:43**********************************@microsof t.com...
> System.Diagnostics.Process.Start(Application.Start upPath &
> "\filename.pdf")
>
> But this did not work ...
Look at the ProcessStartInfo class - its UseShellExecute property allows
you to "launch" files just like explorer.
Imports SI=System.IO
Dim ps as New ProcessStartInfo()
With ps
.Filename = SI.Path.Combine( Application.StartupPath,
"filename.pdf" )
.UseShellEexecute = True
End With
Dim p as New Process
p.StartInfo = ps
p.Start()
HTH,
Phill W.