Click here to Skip to main content
Click here to Skip to main content

Icon Extractor in VB.NET

By , 12 Apr 2004
 

Introduction

In my years of developing windows applications, finding the best icons is sometimes the most difficult thing to do. When I eventually settle on one, I always wonder if there was something better that I could have used. What I've developed here, is an Icon Extractor. Point the application to a directory, and let it run... It scans every DLL, EXE, and ICO file in every directory under the one you provide (can be edited to scan other files too like OCX's). I hope some of you find this useful for your own development. The demo application is really quite quick as well. It scanned 10 GB worth of files and came up with 6182 icons in 10:33 minutes! I also have to admit that it's fun to watch it run through all the files on your computer and watch the forms' icon flash through about 50 icons in a second!

Background

The general idea is to pull out icons that are embedded resources to DLL's or EXE's. The way it's done is with the old fashioned Win32 API's. I had intended to use .NET's System.Reflection.Assembly.GetEmbeddedResource function, but this only works for managed assemblies. I found that the API's work on anything.

Using the code

When you click the button, here's what happens:

  • Load a DirectroyInfo object based on user input.
  • Use GetDirectories in conjunction with GetFiles to find all the file types that might have an icon in them.
  • While looping through the files, extract each icon that's available, and save it to a directory using a FileStream
  • That's pretty much it.

Below is the class used to extract all the icons.

[ Editor Note - the lines have been wrapped to avoid scrolling]
Imports System
Imports System.IO
Class IconExtractor
    'First, lets declare the API's we'll need.
#Region "API's"
    Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" _
            (ByVal lpszFile As String, _
             ByVal nIconIndex As Integer, _
             ByRef phiconLarge As Integer, _
             ByRef phiconSmall As Integer, _
             ByVal nIcons As Long) As Integer
    Declare Function DestroyIcon Lib "user32.dll" 
     (ByVal hIcon As Integer) As Integer
    Declare Function GetStockObject Lib "gdi32.dll" 
     (ByVal nIndex As Integer) As Integer
    Declare Function DrawIconEx Lib "user32.dll" 
     (ByVal hdc As Integer, ByVal xLeft As Integer, ByVal yTop As Integer, 
     ByVal hIcon As Integer, ByVal cxWidth As Integer, ByVal cyWidth As Integer, 
     ByVal istepIfAniCur As Integer, ByVal hbrFlickerFreeDraw As Integer, 
     ByVal diFlags As Integer) As Integer
    Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" 
     (ByVal hInst As Integer, ByVal lpszExeFileName As String,
      ByVal nIconIndex As Integer) As Integer
#End Region

    ' keeps track of what to name each file to create. 
    Private intIconNumber As Long = 0

    ' keeps track of how many icons we've created.
    Private intIconCount As Long = 0

    'holds an array of BASE64 strings which representPrivate 
    'ar As New SortedList
    'each icon that we've written. This is used to make sure 
    'we don't create duplicate icons.
    Private ar As New SortedList

    'determines where the files are to be put.
    Private destinationFolder As String = ""

    'variable to determine if we care about duplicate icons.
    Private blnCheckForDupes As Boolean

    'keeps track of the folder we are processing: sent to client in event
    Private strCurrentFolder As String

    'keeps track of the file we are processing: sent to client in event
    Dim strCurrentFile As String

    'Current numbered directory we're working on, 
    'used to determine percent complete
    Private intFolderX As Integer

    'total number of directories/sub directories we've got to look at
    Private intFolderY As Integer

    'the file types we'd like to look for icons in
    Private strFilterAr() As String

    'the parent form that's calling this class. needed to draw the icon on.
    Private frmParent As Form

    'variable to hold the icon in
    Private icon As icon

    Public Event On_Progress(ByVal folder As String, 
     ByVal file As String, ByVal searchingForDupes As Boolean,
      ByVal folderX As Integer, ByVal folderY As Integer, 
      ByVal totalIconsFound As Integer)
    Public Event On_Complete(ByVal totalIconsFound As Integer)
    Public Event LoadingCurrentIcons(ByVal current As Integer, 
     ByVal total As Integer)

    'calls API to determine how many icons are embedded in the file
    Private Function GetNumberOfIcons(ByVal fl As String) As Integer
        Return ExtractIconEx(fl, -1, 0, 0, 0)
    End Function

    'Extracts each icon from the file given, and saves 
    'it to the destination directory
    Private Sub ExtractIconsFromFile(ByVal f As FileInfo)
        Dim numicons As Integer  ' number of regular icons in the file
        Dim retval As Integer  ' return value
        numicons = GetNumberOfIcons(f.FullName)

        For i As Integer = 0 To numicons - 1
            retval = ExtractIcon(frmParent.Handle.ToInt32,
              f.FullName, i) '?Me.Handle?
            If retval > 0 Then
                Dim stream As New IO.MemoryStream
                frmParent.Icon = icon.FromHandle(New IntPtr(retval))
                Application.DoEvents()
                frmParent.Icon.Save(stream)

                Dim b(stream.Length) As Byte
                stream.Position = 0
                stream.Read(b, 0, stream.Length)
                stream.Close()
                Dim blnOkToCreate As Boolean

                If blnCheckForDupes = False Then
                    blnOkToCreate = True
                ElseIf blnCheckForDupes Then
                    RaiseEvent On_Progress(strCurrentFolder, 
                     strCurrentFile, True, intFolderX, intFolderY,
                      intIconCount)
                    blnOkToCreate = Not IconExists(b)
                    RaiseEvent On_Progress(strCurrentFolder, 
                     strCurrentFile, False, intFolderX,
                      intFolderY, intIconCount)
                End If
                If blnOkToCreate Then
                    Try
                        ar.Add(Convert.ToBase64String(b), intIconNumber)

                        Dim strIcon As New IO.FileStream(
                         destinationFolder & intIconNumber & ".ico", 
                         IO.FileMode.CreateNew)
                        strIcon.Write(b, 0, b.Length)
                        strIcon.Close()
                        intIconNumber += 1
                        intIconCount += 1
                        RaiseEvent On_Progress(strCurrentFolder, strCurrentFile,
                          False, intFolderX, intFolderY, intIconCount)

                    Catch ex As Exception
                    End Try
                End If
            End If
            DestroyIcon(retval)

        Next

    End Sub

    'Checks the array for the same key
    Private Function IconExists(ByVal b() As Byte) As Boolean
        Dim strCurrent As String = Convert.ToBase64String(b)
        For Each strKey As String In ar.Keys
            If strKey = strCurrent Then Return True
        Next
        Return False
    End Function

    'Called if we need to check the directory for what 
    'icons are allready in there. 
    'This way, we can call this class any time, and save icons 
    'to the same directory without
    'worrying about duplicates.
    Private Sub LoadCurrentIcons()
        Dim fi() As FileInfo = New DirectoryInfo(
         destinationFolder).GetFiles("*.ico")
        Dim s As IO.BinaryReader
        Dim str As String
        Dim i As Integer = 1
        For Each f As FileInfo In fi
            RaiseEvent LoadingCurrentIcons(i, fi.Length)
            Try
                Dim fStream As New FileStream(f.FullName, FileMode.Open)
                Dim br As New BinaryReader(fStream)
                Dim bc() As Byte 'current files bytes
                bc = br.ReadBytes(fStream.Length)
                fStream.Close()
                Try
                    ar.Add(Convert.ToBase64String(bc), i)
                Catch ex As Exception
                    'possibility of there being a dupe in the folder already.
                End Try

                i += 1

            Catch ex As Exception

            End Try

        Next

    End Sub

    'Get everything we need to get going. 
    Public Sub New(ByRef fHandle As Form, ByVal folderPath As String,
      ByVal dFolder As String, ByRef hIcon As icon, 
      ByVal checkForDupes As Boolean, ByVal filter() As String)
        Try
            If Not IO.Directory.Exists(dFolder) Then 
             IO.Directory.CreateDirectory(dFolder)
        Catch ex As Exception
            Throw New ArgumentException(
             "The folder specified could not be found or created.")
        End Try

        While IO.File.Exists(destinationFolder & intIconNumber & ".ico")
            intIconNumber += 1
        End While
        ar.Add("blah", 0) 'start the array off
        If Right(dFolder, 1) = "\" Or Right(dFolder, 1) = "/" 
         Then destinationFolder = dFolder Else destinationFolder &= "\"

        icon = hIcon
        blnCheckForDupes = checkForDupes
        strFilterAr = filter
        strCurrentFolder = folderPath
        frmParent = fHandle
    End Sub

    'Called with no parameters to simplify threading options.
    Public Sub ExtractIcons()

        Dim intCounter As Integer = 0
        'for string list
        Dim lstStringFolders As New ArrayList
        Dim strSubFolders As String()
        'for sorted object list
        Dim lstSortedFolders As New ArrayList

        'seed string list
        lstStringFolders.Add(strCurrentFolder)

        'Load the icons that we currenlty have in the directory. 
        'Use these as a base when comparing for duplicates.
        If blnCheckForDupes Then LoadCurrentIcons()

        'as a string list - just gives you a list of the
        ' folders that exist in the path
        Do Until intCounter = lstStringFolders.Count

            intFolderX = intCounter
            intFolderY = lstStringFolders.Count

            RaiseEvent On_Progress(strCurrentFolder, strCurrentFile, 
             False, intFolderX, intFolderY, intIconCount)

            Try
                strSubFolders = System.IO.Directory.GetDirectories(
                 lstStringFolders.Item(intCounter))

                lstStringFolders.AddRange(strSubFolders)

                'get all files in this folder:
                Dim d As New DirectoryInfo(lstStringFolders(intCounter))
                strCurrentFolder = d.FullName

                'make sure we're not looking in the directory we're writing to.
                If Right(strCurrentFolder, 1) = "\" Or
                  Right(strCurrentFolder, 1) = "/" Then
                    If strCurrentFolder.ToLower = destinationFolder.ToLower 
                     Then Exit Try
                Else
                    If d.FullName & "\".ToLower = 
                     destinationFolder.ToLower Then Exit Try
                End If

                'don't look in the recycle bins:
                If d.FullName.ToLower.IndexOf("recycler") > -1 Then Exit Try

                RaiseEvent On_Progress(strCurrentFolder, "", False, 
                 intFolderX, intFolderY, intIconCount)

                Dim fl() As FileInfo

                For Each sFilter As String In strFilterAr
                    fl = d.GetFiles(sFilter)
                    For Each f As FileInfo In fl
                        RaiseEvent On_Progress(strCurrentFolder,
                         f.Name, False, 
                         intFolderX, intFolderY, intIconCount)
                        ExtractIconsFromFile(f)
                    Next
                Next


            Catch ex As Exception

            End Try

            intCounter += 1
        Loop

        RaiseEvent On_Complete(intIconCount)

    End Sub
End Class
      
      

The form itself should use addHandler or dim the class withEvents to expose the events.

[ Editor Note - the lines have been wrapped to avoid scrolling]
Private t As DateTime
Const destDir As String = "C:\icons2\"
Private strFilter() As String = {"*.dll", "*.exe", "*.ico"}
Private th As Threading.Thread

'starts the whole thing off.
Private Sub Button2_Click(ByVal sender As System.Object, 
 ByVal e As System.EventArgs) Handles btnStart.Click
    If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
        Dim objIconExtractor As New IconExtractor(Me, 
         FolderBrowserDialog1.SelectedPath, destDir, Me.Icon, 
         chkNoDuplicates.Checked, strFilter)
        AddHandler objIconExtractor.On_Progress, 
         AddressOf UpdateUI
        AddHandler objIconExtractor.On_Complete, 
         AddressOf Completed
        AddHandler objIconExtractor.LoadingCurrentIcons, 
         AddressOf LoadingCurrentIcons
        th = New System.Threading.Thread(
         AddressOf objIconExtractor.ExtractIcons)
        th.Start() 'put the function into its own thread so 
         'I can cancel it, and move the form around.
        btnStop.Enabled = True
        chkNoDuplicates.Enabled = False
        btnStart.Enabled = False
        Application.DoEvents()
        t = New DateTime
        Timer1.Enabled = True 'timer to keep track of time elapsed. 
    End If
End Sub

'Handles when the class raises the On_Progress Event... 
'Lets tell the user where we are, and what we're up to:
Private Sub UpdateUI(ByVal folder As String, ByVal file As String, 
 ByVal searchingForDupes As Boolean, ByVal folderX As Integer, 
 ByVal folderY As Integer, ByVal totalIconsFound As Integer)
    lblFolder.Text = folder
    lblFile.Text = file
    If searchingForDupes Then lblProgress.Text = 
     "Scanning for duplicates..." Else lblProgress.Text = ""
    Try
        Dim percent As Integer = CInt((folderX / folderY) * 100)
        lblPercent.Text = percent & "%"
    Catch
    End Try
    ProgressBar1.Maximum = folderY
    ProgressBar1.Value = folderX

    Label2.Text = "New Icons Found: " & totalIconsFound
    Application.DoEvents()
End Sub

'All done
Private Sub Completed(ByVal intCount As Integer)
    ClearUI()
    Label2.Text = "Done: " & intCount & 
     " new icons were created."
    Timer1.Enabled = False
    btnStart.Enabled = True
    btnStop.Enabled = False
    chkNoDuplicates.Enabled = True
End Sub

'initialize the labels.
Private Sub ClearUI()
    lblFile.Text = ""
    lblFolder.Text = ""
    lblProgress.Text = ""
    lblPercent.Text = ""
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, 
 ByVal e As System.EventArgs) Handles MyBase.Load
    ClearUI()
End Sub

'Cancel the thread if its still running. 
Private Sub btnStop_Click(ByVal sender As System.Object, 
 ByVal e As System.EventArgs) Handles btnStop.Click
    btnStop.Enabled = False
    Application.DoEvents()
    th.Abort()
    While Not th.ThreadState = Threading.ThreadState.Stopped
     'Wait for it to stop before continuing
        Threading.Thread.Sleep(250)
    End While
    Timer1.Enabled = False
    btnStart.Enabled = True
    chkNoDuplicates.Enabled = True
End Sub

'let the user know that we're loading the icons 
'that already exist in the given directory.
Private Sub LoadingCurrentIcons(ByVal current As Integer, 
 ByVal total As Integer)
    lblProgress.Text = "Loading current icons: " & 
     current & " of " & total & "."
    Application.DoEvents()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object,
  ByVal e As System.EventArgs) Handles Timer1.Tick
    t = t.AddSeconds(1)
    lblTime.Text = t.TimeOfDay.ToString
    Application.DoEvents()
End Sub

'Be absolutely sure that the other thread is done,
' otherwise we really don't exit.
Private Sub Form1_Closing(ByVal sender As Object,
  ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    Try
        Me.Cursor = Cursors.WaitCursor
        If Not th Is Nothing Then
            If Not th.ThreadState = Threading.ThreadState.Stopped 
                  Then th.Abort()

            While Not th.ThreadState = Threading.ThreadState.Stopped
                Try
                    Threading.Thread.Sleep(100) 'this forms thread
                Catch ex As Exception

                End Try
            End While
        End If
    Catch ex As Exception
    End Try
End Sub

Points of Interest

I found that being able to run this multiple times, and always have the most current icons that are on my system are very beneficial. I can find an icon for almost any need.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Domenic
Web Developer
United States United States
Member
I've been writing software applications since the early 90's from ASP and VB5 to C# and ASP.NET. I am currently working on law enforcement and criminal justice applications delivered over the web. I've always been astounded by the fact that the only 2 industries that refer to customers as "users" are narcotics and software development. Wink | ;-)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalerror :(memberInfinity82718 Mar '11 - 13:03 
I keep getting some error saying The folder specified could not be found or created Frown | :( Help is appreciated Smile | :)
GeneralGreat tool - thank you!memberTorstenTiedt3 Jan '10 - 1:59 
Worked perfect!
GeneralThank You!memberPaleogirl200327 Mar '09 - 7:53 
Thank You - I was trying to make one myself and ran across this!
Questionlow colour depth?membericelava5 Jul '07 - 23:51 
Nice tool, I managed to modify the code to properly handle multi-threaded Windows operations, but I found that the extracted icons, nearly 20000 of them, all have poor colour depth. What can be the cause for such low colour output?
 
The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

AnswerRe: low colour depth?memberjoepsy24 Jul '08 - 2:04 
The answer can be found on
http://www.vbforums.com/showthread.php?t=396650
I will try this now...
GeneralReally Goodmemberr.brunt23 Nov '06 - 11:01 
This is a really good app, I have been looking for something that does this sort of thing as a batch process, and I think I have found it!
 
For some reason, a few of the icons that were extracted were quite distorted, any ideas why?Confused | :confused:
GeneralThanksmemberJason Vetter18 Nov '06 - 6:57 
Very sloppy code but i still appreciate your contribution.
 
In the future perhaps you could do a few things:
 
1) Use Option Strict so you actually use correct data types
2) Design your classes more flexible so that they may be used more generically.
 
Having to create the class, for example, by passing a ByRef Form object is rediculous.
Put the ability to extract and save icons as methods and allow properties such as where to save to, where to look from, etc..
GeneralAwesome tool. Thanks. (NT)memberJosh.Young4 Oct '06 - 10:34 
..
QuestionWhat if I wanted to replace an iconmemberprojecthiphop12 Sep '06 - 11:10 
This is a really cool app! Nice work! I need to know how to replace a folders icon through my code. Any ideas?
Questionhow can i program with using some of recycle bin propertiesmembersyriast30 Jul '06 - 3:20 
i want to make a program put it icon on desktop to droped file on it like recyclebin whin droped the file on icon give me messege in path of file droped
thanks
AnswerRe: how can i program with using some of recycle bin propertiesmemberDomenic31 Jul '06 - 7:44 
That is a bit outside of the scope of this article, but... just call Command() in your form load or Main() entry point. That will give you the whole command line. You'll need to parse it out yourself using substring or something. Otherwise, if you use C#, you'll get a function static void Main(string[] args) which gives you an array of all the items sent to the exe. This works for drag/drop files, or you could just run the application from the command line with the argurment (i.e. myprogram.exe "C:\myfile.abc". Good luck.
GeneralIcon Extractor (I LOVE IT)memberGrumpy Aero Guy17 Jun '06 - 6:06 
Big Grin | :-D
 
Awesome.....
 
FANTASTIC....
 
This is a GREAT tool....
 
Grumpy Aero Guy
GeneralRe: Icon Extractor (I LOVE IT)memberDomenic31 Jul '06 - 7:45 
Thanks, I appreciate that.
GeneralCursorsmemberD1115 Jun '06 - 2:38 
Can you develop/point me to API's to extract cursors instead?
GeneralThanks!memberD11126 May '06 - 8:06 
Guess how I found your article?! Big Grin | :-D
I was trying to write something like this myself and did a search for methods to extract icons, I'm clueless when it comes to Windows API's Frown | :( (Perhaps someone can point me to help!), and I was getting desperate Sigh | :sigh: , I had gone through quite a few articles and then I found yours! Smile | :)
Great Code.
Full Marks!
GeneralGood JobmemberPolymorpher3 Feb '06 - 4:05 
There will always be critisism but thats how we continue to learn...The project is great and will help alot of other programers. Thanks for sharing
 
Pablo
GeneralIs it legal to use an icon from another programmemberchadbellan23 Dec '05 - 4:21 
I wanted to know if it was legal to use an icon from another program, library, etc...
GeneralRe: Is it legal to use an icon from another programmemberNassir200512 May '06 - 21:42 
Of course it is not legal, but for the purpose of "Know How", I guess no problem;).
GeneralRe: Is it legal to use an icon from another programmemberFrancois Venter4 Mar '08 - 2:17 
If you dont sell the content the it is ok. WTF | :WTF:
GeneralRe: Is it legal to use an icon from another programmemberBruno Cossi15 Mar '09 - 15:23 
Actually whether you sell it or not does not matter - it is illegal to use the icon unless the owner has expressly given the permission.
Cool tool either way.
GeneralCross Thread Operation Errormemberdlarkin7715 Dec '05 - 23:07 
Hi,
 
I've just started learning VB.Net and I downloaded this code. It had to be converted to VB.Net 2005. I'm getting an error in the UpdateUI subroutine at the line lblFolder.Text = folder
 
The error is as follows
Cross thread operation not valid : Control lblFolder accessed from a thread other than the thread it was created on
 
Any ideas how this can be fixed? As I said I'm new to VB.Net and I don't have any idea how to do this myself.
 
Thanks very much,
 
dlarkin77
GeneralRe: Cross Thread Operation ErrormemberDomenic16 Dec '05 - 2:43 
Threading has changed a bit in .net 05. There's an article that explains either how you can disregard the error checking, or fix the code to be more thread safe. Article is here: http://msdn2.microsoft.com/en-us/library/ms171728.aspx[^] good luck!
GeneralRe: Cross Thread Operation Errormemberdlarkin7716 Dec '05 - 3:40 
Thanks for pointing me to that article. Does this mean that I should have a seperate function/subroutine for each UI component that needs to be updated?
 

GeneralRe: Cross Thread Operation ErrormemberDomenic16 Dec '05 - 4:06 
That seems to be the case. I haven't played too much with VS 05, so I'm not sure. It looks like if a separate thread tries to update the UI control, then yes, you'll need a separate function to handle it that is thread safe.
GeneralRe: Cross Thread Operation ErrormemberD11126 May '06 - 7:35 
I've played a bit with threads in VB 05. You don't have to have a seperate Sub/Function for each control. Big Grin | :-D
 
You can use 1 Sub/Function for all cros-thread operations you'll ever use!
 
'A delegate for the cross-thread operations
Private Delegate Sub CrossThreadDelegate(ByVal WhatToDo As String)
 
Private Sub CrossThread(ByVal WhatToDo As String)
Select Case WhatToDo
'Insert Case Statements and Code
End Select
End Sub

 
Whenever you use a cross-thread operation use the following:
If [ControlToUpdate].InvokeRequired Then
Dim del As New CrossThreadDelegate(AddressOf CrossThread)
[ControlToUpdate].Invoke(del, New Object() {Arguments for Sub here. In this case the string 'WhatToDo' argument.})
Else
'Normal Code Here (That would be contained in sub)
End If

 
You could also make 1 sub for each control whose text you need to cange, etc...

GeneralRe: Cross Thread Operation Error [modified]memberD11126 May '06 - 7:48 
Adding to the last reply:
 
Heres an example:
 
Private Delegate Sub SetTextThreadSafe(ByVal ControlToSet As Control, ByVal SetTo As String)
 
Private Sub ChangeText(ByVal Control As Control, SetTo As Strimg)
Control.Text = SetTo
End Sub
 
Private Sub CallThisFromAnotherThread()
'This assumes that there is a label called lblLabel
'And a textbox called txtText
Dim del As New SetTextThreadSafe(AddressOf ChangeText)
If lblLabel.InVokeRequired Then
lblLabel.Invoke(del, New Object {lblLabel, "New Text"})
'lblLabel.Invoke can be any Invoke Method
Else
lblLabel.Text = "New Text"
End If
'Do the same for the textbox
If txtText.InvokeRequired Then
txtText.Invoke(del, New Object() {txtText, "Text box text"})
Else
txtText.Text = "Text box text"
End If
End Sub

 
Hope it helps. Smile | :)
 

-- modified at 13:49 Friday 26th May, 2006
GeneralRe: Cross Thread Operation Errormemberjoepsy24 Jul '08 - 2:17 
The easiest fix for this app is: add the line
 
System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = False
 
to Form1_Load (in Form1.vb)
GeneralWrong Declaration for ExtractIconExmemberThe_Mega_ZZTer18 Nov '05 - 13:41 
.NET 2.0 will detect and halt the invalid declaration, 1.1 doesn't care
 
The last parameter should be an Integer or a Uint, not a Long.
GeneralExport data as CSV file in VB.NETmemberapvb200425 Aug '05 - 4:59 
Hello all,
 
I need to export a SQL table to the CSV file with it's headings on button click event in vb.net. Can anyone tell me how would I do it.
 
Any help would be really appreciated,
 
Thanks,
 
-A
GeneralRe: Export data as CSV file in VB.NETmemberDomenic1 Sep '05 - 7:35 
You're really posting this in the wrong place, but it is quite easy to do. Run your query and put it into a dataReader object. Follow the code on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhcvs04/html/vs04g6.asp[^] for getting column names and looping through each row of data. It should be relatively easy to write each value in quotes, followed by a comma, and at the end of a row append a carriage return. SQL Enterprise Manager can let you export data as CSV as well, but I see you're trying to do it at a button event. Good luck.
GeneralYou starmemberGav_Roberts2k518 Aug '05 - 22:44 
I spent a good while last night trying to extract the icons from my shell32.dll using some poxy software that done it all wrong.
 
This is innovative stuff, you have software out there that does many things, but yours is simple and does exactly what is says on the tin.
 
5 stars mate.
 
Life Saver
 
Gav
QuestionWhy? Why? Why?sussAnonymous12 Nov '04 - 6:14 
I saw u used this procedure to save the icon to a file....
THIS........
Dim stream As New IO.MemoryStream
Icon.Save(stream)
 
Dim b(CInt(stream.Length)) As Byte
stream.Position = 0
stream.Read(b, 0, CInt(stream.Length))
stream.Close()
 
Dim fs As New IO.FileStream(FileName, IO.FileMode.CreateNew)
fs.Write(b, 0, b.Length)
fs.Close()
OR THIS.........
Icon.Save(sfd.OpenFile)
 
I tried the code out thinking maybe that this is the workaround for the Icon.Save function, but obviously it works exactly the same. could it be u dont know about Icon.Save?

GeneralIcon stripsmemberstaceyw22 Jul '04 - 13:46 
Could it do/find icon Strip images (not sure if bmp, ico, other) or other images in dlls, ocx, msc, etc.
That would be cool. Nice program. Cheers!
 
William Stacey - MVP
GeneralSuggested changemembertlanier18 Jul '04 - 7:57 
The current program always initializes the intIconNumber value to zero. To allow unique file names each time the program is run, add the following to the LoadCurrentIcons() method.
 
Private Sub LoadCurrentIcons()
 
...
 
try
'find name with largest icon number
n = CInt(System.IO.Path.GetFileNameWithoutExtension(f.FullName))
If n >= intIconNumber Then
intIconNumber = n + 1
End If
 
...
GeneralPut icons in imagemembermilhouse6913 May '04 - 14:22 
Hi Domenic, first of all you project is great ! Smile | :)
but i got a question: is there a way to put the stream in a image (object) or an imagelist in .NET?
it would be pretty nice if you can help me on this, you can email me ! Smile | :)
 
- Pascal
GeneralRe: Put icons in imagememberDomenic17 May '04 - 7:47 
Hello.
I haven't tested it, but I think you can do that... The new constructor of the icon class takes a stream as a parameter, so I imageine that's the way to do it... Try something like: ImageList1.Images.Add(new Icon(stream)). Good luck!
GeneralRe: Put icons in imagememberD11126 May '06 - 7:53 
Icon isn't inherited from image so you can't use Imagelist1.Images.Add(Icon).
 
Use:
Imagelist1.Images.Add(Icon.ToBitmap)
GeneralIcons Format in 16 colorsmemberJoao Guimaraes29 Apr '04 - 3:44 
In my computer, after running the extractor, all icons are with 16 colors only .. shouldn´t they be as the originals?
GeneralRe: Icons Format in 16 colorsmemberDomenic3 May '04 - 8:24 
This is as designed with the ExtractIcon API. The API extracts the icon that best suits the settings of the machine (see http://www.pcmag.com/article2/0,1759,1167144,00.asp for details). If you know a way to get the highest resolution icon out of the file, please post it here. Thanks!
GeneralRe: Icons Format in 16 colorsmemberYangghi Min12 May '04 - 14:39 

I'd like to recommend you to refer to one of the Platform SDK sample,
'IconPro'.
 
Although it was written in C using Win32 SDK API, I guess it would be a great help to anyone who is interested in the ICON interface.
 
Have a nice day!
GeneralDestination DirectorymemberWolf4web21 Apr '04 - 0:04 
Very nice tool. I have been looking for something like this...
 
Just one comment: I started the tool and everything looked fine, I just couldn't find the output directory. After poking around in the sources, I determined, that it was hard coded to 'c:\icons2', which might not work for people that have no c: drive, not enough space on it, etc...
Maybe you could make it a command line parameter or a form field for a future release? But on the other hand, with the source code in hand, people could do this themselves.
 
Fine work!
GeneralRe: Destination DirectorymemberDomenic21 Apr '04 - 1:57 
Ah yes... I forgot to pull that c:\icons2 variable out, and make it into a user defined variable... but true, if you have the source, it's easy enough to change. Thanks!
GeneralCoolmemberMark Pitman13 Apr '04 - 13:30 
Cool, I was going to write something like this myself. Now I don't have to bother with it!
GeneralRe: CoolmemberDomenic14 Apr '04 - 6:43 
Thanks Mark. I appreciate your comment... I hope you find this tool useful.
dom
GeneralRe: CoolmemberBug Chaser24 Apr '04 - 5:24 
This definately is a time saver!
Thank you Domenic
Glen
 
--------------------------
from: bug_Chas3r@myway.com
--------------------------
GeneralRe: CoolmemberRicalawaba22 May '05 - 7:43 
Same comment.
 
Cool Code and App
QuestionWhy? Why? Why?sussA-n-d-r-e-w-v-o-s--cantbetaken12 Nov '04 - 6:15 
I saw u used this procedure to save the icon to a file....
THIS........
Dim stream As New IO.MemoryStream
Icon.Save(stream)
 
Dim b(CInt(stream.Length)) As Byte
stream.Position = 0
stream.Read(b, 0, CInt(stream.Length))
stream.Close()
 
Dim fs As New IO.FileStream(FileName, IO.FileMode.CreateNew)
fs.Write(b, 0, b.Length)
fs.Close()
OR THIS.........
Icon.Save(sfd.OpenFile)
 
I tried the code out thinking maybe that this is the workaround for the Icon.Save function, but obviously it works exactly the same. could it be u dont know about Icon.Save?

AnswerRe: Why? Why? Why?memberDomenic12 Nov '04 - 6:25 
Yes, I do know about the icon.save method. I remember trying to use that at one point, but had some issue with it. I can't recall what it was. If it works for you, then great.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 13 Apr 2004
Article Copyright 2004 by Domenic
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid