Answered by:
Getting the icon from a single file instead of the icons from the files in a folder.

Question
-
Dim thepath As String = TextBox1.Text For Each files In System.IO.Directory.GetFiles(thepath.Remove(thepath.LastIndexOf("\"))) Dim icons As Icon = Icon.ExtractAssociatedIcon(files) ImageList1.Images.Add(icons) ListView1.Items.Add(files.ToString, ImageList1.Images.Count) Next
I'm using the code abvove and think I have to change this line of code in order to get the icon from a single file instead of the icons from all the files in a folder.
For Each files In System.IO.Directory.GetFiles(thepath.Remove(thepath.LastIndexOf("\")))
The textbox1 = a exe file path for example >>> "C:\Program Files (x86)\iTunes\iTunes.exe"
Tuesday, March 19, 2013 9:03 PM
Answers
-
No need for a loop...if it is just one file
Dim thefile As String = TextBox1.Text Dim icons As Icon = Icon.ExtractAssociatedIcon(thefile) ImageList1.Images.Add(icons) ListView1.Items.Add(files, ImageList1.Images.Count)
Tuesday, March 19, 2013 9:17 PM
All replies
-
No need for a loop...if it is just one file
Dim thefile As String = TextBox1.Text Dim icons As Icon = Icon.ExtractAssociatedIcon(thefile) ImageList1.Images.Add(icons) ListView1.Items.Add(files, ImageList1.Images.Count)
Tuesday, March 19, 2013 9:17 PM -
It doesn't work it don't get any icons at all now I think I only need the edit this line>
For Each files In System.IO.Directory.GetFiles(thepath.Remove(thepath.LastIndexOf("\")))
Tuesday, March 19, 2013 9:25 PM -
If you want to get the icon for the file whose path is in TextBox1.Text, the code posted by That Would be me will do that. If that code doesn't work for you, you must want to do something else. Can you explain in more detail what it is you want to do?Tuesday, March 19, 2013 9:34 PM
-
You're code on my previous thread was fine but I made a mistake a don't want all the icons from the folder in witch the program is located but only the icon for the program it self. So I think in this code>
For Each files In System.IO.Directory.GetFiles(thepath.Remove(thepath.LastIndexOf("\")))
.Remove(Lastindexof("\"))) can be reomved and the words Directory and mabye also GetFiles need to be change.
Tuesday, March 19, 2013 9:56 PM -
If "The textbox1 = a exe file path for example >>> "C:\Program Files (x86)\iTunes\iTunes.exe"" then you don't need the loop or the getfiles. it's just
Dim thePath As String = TextBox1.Text
Dim icons As Icon = Icon.ExtractAssociatedIcon(thePath)
ImageList1.Images.Add(icons)
ListView1.Items.Add(files.ToString, ImageList1.Images.Count)see:
If that doesn't work then the textbox does not really contain the path to an exe, or the exe does not contain an icon. Why were you using a loop in the first place if you only wanted one icon from the file named in the text box?
http://msdn.microsoft.com/en-AU/library/system.drawing.icon.extractassociatedicon.aspx- Edited by Acamar Tuesday, March 19, 2013 10:29 PM sp
Tuesday, March 19, 2013 10:24 PM -
You're code on my previous thread was fine but I made a mistake a don't want all the icons from the folder in witch the program is located but only the icon for the program it self.
Tuesday, March 19, 2013 10:31 PM