Hi Guys,
I posted on another part of the site and was advised to post here, i am currrently developing a small program, all i want it to do is pick up shortcuts from a directory i specify and list them in a listview box and allow me to click them and open the shortcuts in the default program for the file! So far i am able to list the files i need and i have found some code on the web that will (i hope) allow me to open the files when they are clicked, but when i click the file i get an error saying it cannot start the process as the filename has not been provided, here is my code:
************************************************** ***********************************
************************************************** ***********************************
Public Class QuickStart
Private Sub QuickStart_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim di As New IO.DirectoryInfo("C:\QuickStart")
Dim aryFi As IO.FileInfo() = di.GetFiles("*.*")
Dim fi As IO.FileInfo
For Each fi In aryFi
ListView1.Items.Add(ClipExt(fi.Name))
Next
End Sub
Private Function ClipExt(ByVal fname As String) As String
Dim nPos As String
nPos = InStrRev(fname, ".")
If nPos > 0 Then
fname = mid(fname, 1, nPos - 1)
End If
ClipExt = fname
End Function
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim psi As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo()
psi.FileName = Me.ListView1.SelectedItems(0).Name
psi.UseShellExecute = True
psi.ErrorDialog = True
Try
System.Diagnostics.Process.Start(psi)
Catch ex As Exception
MessageBox.Show(Me, "Couldn't open the file!\n" + ex.ToString(), "Explorer XTreme")
Finally
psi = Nothing
End Try
End Sub
End Class
************************************************** ***********************************
************************************************** ***********************************
I am assuming it is something to do with my loop at the begining of the code not passing the file name and location to something like an array? i could be wrong! i am using VB 2005 Express, is anyone able to help?
Kind Regards
Jay!