Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I started creating an application launcher that pulls application shortcuts from a folder and list them with the icon and on click the application opens.

The issue im having is when i run it i get .lnk at the end of the shortcuts and all i want is just the name. Help would be great and please no links to other items to read i need help with the code.

VB
Private Sub Application_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Dir As New DirectoryInfo("C:\Remote Tools")
FillListView(Dir)

end sub




VB
Private Sub FillListView(ByVal Folder As DirectoryInfo)
        Static ImageList As New ImageList With {.ColorDepth = ColorDepth.Depth32Bit, .ImageSize = New Size(20, 20)}
        Static ImgIndex As Integer = 0

        ListView1.LargeImageList = ImageList
        ListView1.View = View.Tile


        For Each F As FileInfo In Folder.GetFiles("*.lnk")
            ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
            ListView1.Items.Add(F.Name, ImgIndex).Tag = F
            ImgIndex += 1
        Next


        For Each Dir As DirectoryInfo In Folder.GetDirectories
            FillListView(Dir)
        Next
    End Sub
Posted

1 solution

Seriously, read MSDN documentation.

The following function and a buch of other in that Path class will hell you a lot with file name manipulation.

Path.GetFileNameWithoutExtension Method [^]

By the way, Google is a good tool to find in seconds the answer to such questions.
 
Share this answer
 
Comments
Zachary.shupp 3-Feb-12 20:14pm    
I understand that google is a good method but i m new to vb and sometimes it just nice to see how to use some of the code. I have looked at what you listed and i dont know how to include it towhat i have. my main goal is to have the icon with the text which i have gotten but getting the ,lnk to drop off is harder then i thought.
Philippe Mori 3-Feb-12 20:34pm    
When you add an item with F.Name to the list view, use the GetFileNameWithoutExtension method to remove the extension. Very easy.
Zachary.shupp 3-Feb-12 22:25pm    
okay i see what your saying but if you can show me that would be great. i tried
ListView1.Items.Add(F.Name, GetFileNameWithoutExtension ,ImgIndex).Tag = F
and it didnt work.
Sergey Alexandrovich Kryukov 4-Feb-12 3:23am    
"Did not work" is not informative. Your problem is not that you are "new to VB" (which is not VB, this is VB.NET, a totally different language), but that you are 1) using is as excuse, which is irrelevant, 2) not trying to think logically. Laziness in thinking? Won't help.
--SA
Philippe Mori 4-Feb-12 7:55am    
I don't know much VB.NET (I uses C#) but if you look the line just before, you should be able to figure out the syntax. And by the way, what is the purpose of the = F at the end of the line.
If you don't understand how to write it in a single line, then uses an intermediaite variable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900