473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Opening files in Listview box

30
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!
Mar 26 '08 #1
1 969
Shashi Sadasivan
1,435 Expert 1GB
look at the code when the selected item is to be opened
psi.FileName = Me.ListView1.SelectedItems(0).Name

in your initial loop where you populate the list, you are cliping the extension, and only using the file name (not path)
So suppose your file is c:\myDirectory\myFile.myext
the list shows myFile
sending myFile as a filename to open will throw an exception.

The best thing you could do is to m,aintain an internal list of all files as fileInfo, probably in a List<FileInfo>, and everytime a shortcut has to be opened, search the filename in the List<FileInfo> whose filename matches with what is selected, and supply the full name of that file from the fileInfo object
Mar 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
0
by: MikeY | last post by:
Hopefully someone can help, I have a listview box where I display my desired files. I single click on the desired file to be renamed and I rename it with a new name. My problem arises when the...
3
by: Wim | last post by:
I'm trying to add files with a OpenFileDialog to a listview. This is what I've come up with sofar: protected void ButAddClick(object sender, System.EventArgs e) { OpenFileDialog MyDialog = new...
2
by: Gos | last post by:
Hi, I have a program that needs to open a list of attachments displayed on a ListView. I have used Process.Start method to open the files using their associated program. This works correctly if...
1
by: Richard | last post by:
If I'm to make a Listview with a list of files, then how can i get the associated icon to match the file?? Meaning I need the Windows Explorer icons to be the same as in my listview. I can...
0
spider1916
by: spider1916 | last post by:
hi there, i need some help on hou to add multiple files selected in an ShowOpen dialog box to my listview. i am using my listview to display all the attached files for an email. i can add a single...
7
by: Asprisa | last post by:
Hi Guys, I am currently developing a small program that will help keep my desktop a bit more organised....(Laughs!) I am creating an application that will sit on my desktop, it has a listview...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
by: Peter Hemmingsen | last post by:
Hi We have a directory receiving PDF files from various scanners. I need a simple to browse these files, view them, and based on the content move them to different applications using drag/drop....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.