none
Showing Drive, Folder and File Icons using Shell32.DLL RRS feed

  • Question

  • Hi Everyone,

    I am working on a project where I need the ability to see hidden Folders and Files. None of the Open dialog controls have that ability, so I was forced to find a workaround.

    The workaround I found was to have three list boxes; one for drives, another for directories(folders) and lastly for files. To make it look more professional, I replaced the Drive list box with a combo box. I can show the drive icons in the combo box. I also want to show the folder icons in the folders list, and ditto for file icons. The form is designed like:

    When running...

    At this time there isn't much code.

    Imports System.Runtime.InteropServices
    Imports System.IO
    Public Class frmMain
    #Region " Declare Ansi Function SHGetFileInfo"
        Private Declare Ansi Function SHGetFileInfo Lib "shell32.dll" _
                (ByVal pszPath As String,
                 ByVal dwFileAttributes As Integer,
                 ByRef psfi As SHFILEINFO,
                 ByVal cbFileInfo As Integer,
                 ByVal uFlags As Integer) As IntPtr
    #End Region
    
    #Region "Structure SHFILEINFO"
        Public Structure SHFILEINFO
            Public hIcon As IntPtr
            Public iIcon As Integer
            Public dwAttributes As Integer
            <MarshalAs(UnmanagedType.ByValTStr,
                       SizeConst:=260)> Public szDisplayName As String
            <MarshalAs(UnmanagedType.ByValTStr,
                       SizeConst:=80)> Public szTypeName As String
        End Structure
    #End Region
    
        Private Const SHGFI_ICON As Integer = &H100
        Private Const SHGFI_SMALLICON As Integer = &H1
        Private Const SHGFI_DISPLAYNAME As Integer = &H200
        Private Const SHGFI_TYPENAME As Integer = &H400
    
        Private Const FILE_ATTRIBUTE_NORMAL As Integer = &H80
    
        Private WithEvents Img1 As New ImageList
    
        Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
            For Each fi In IO.Directory.GetLogicalDrives
                Dim shinfo As New SHFILEINFO()
    
                SHGetFileInfo(fi, FILE_ATTRIBUTE_NORMAL, shinfo,
                              Marshal.SizeOf(shinfo),
                              SHGFI_ICON + SHGFI_SMALLICON +
                              SHGFI_DISPLAYNAME + SHGFI_TYPENAME)
                Dim myIcon As Icon = Nothing
                myIcon = Icon.FromHandle(shinfo.hIcon)
                Img1.Images.Add(myIcon)
            Next
    
            CboDrives.DrawMode = DrawMode.OwnerDrawVariable
            CboDrives.ItemHeight = 20
            CboDrives.Items.AddRange(IO.Directory.GetLogicalDrives)
        End Sub
    
        Private Sub CboDrives_DrawItem(sender As Object,
                                       e As DrawItemEventArgs) _
                                       Handles CboDrives.DrawItem
    
            e.Graphics.DrawImage(img1.Images(e.Index),
                               New Point(1, e.Bounds.Top + 1))
            e.Graphics.DrawString(CboDrives.Items(e.Index).ToString,
                                  CboDrives.Font,
                                  Brushes.Black,
                                  18, e.Bounds.Top + 1)
        End Sub
    
        Private Sub CboDrives_SelectedIndexChanged(sender As Object,
                                                   e As EventArgs) _
                                                   Handles CboDrives.SelectedIndexChanged
            FoldersList.Items.Clear()
    
            Try
                Dim drive As DriveInfo = DirectCast(CboDrives.SelectedItem, DriveInfo)
                For Each dirInfo As DirectoryInfo In drive.RootDirectory.GetDirectories()
                    FoldersList.Items.Add(dirInfo)
                Next
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    End Class
    
    

    I chose to use the Shell32.DLL, because it usually has all the standard icons a programmer needs.

    Does someone know how to place the directory Names along with their icons in a list box using code similar to that shown in the Form_Load event?

    Or if you have a better way please share :-).

    Thanks in advance,


    MRM256

    Friday, January 3, 2020 6:26 PM

Answers

  • The test I did =>

    (initial directory set to "e:\toto1" for testing)

    Dim pFileSaveDialog As IFileDialog
    
    Dim hr As HRESULT = HRESULT.E_FAIL
    Dim CLSID_FileOpenDialog As New Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")
    ' Dim CLSID_FileSaveDialog As New Guid("C0B4E2F3-BA21-4773-8DBA-335EC946EB8B")
    Dim FileSaveDialogType As Type = Type.GetTypeFromCLSID(CLSID_FileOpenDialog, True)
    Dim FileSaveDialog As Object = Activator.CreateInstance(FileSaveDialogType)
    pFileSaveDialog = DirectCast(FileSaveDialog, IFileDialog)
    If (pFileSaveDialog IsNot Nothing) Then
        Dim nOptions As FOS = 0
        hr = pFileSaveDialog.GetOptions(nOptions)
        'nOptions = nOptions Or FOS.FOS_PICKFOLDERS
        nOptions = nOptions Or FOS.FOS_FORCESHOWHIDDEN
        hr = pFileSaveDialog.SetOptions(nOptions)
    
        Dim psi As IntPtr = IntPtr.Zero
        Dim GUID_IShellItem As New Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")
        hr = SHCreateItemFromParsingName("e:\toto1", IntPtr.Zero, GUID_IShellItem, psi)
        If (hr = HRESULT.S_OK) Then
            Dim pShellItem As IShellItem = CType(Marshal.GetObjectForIUnknown(psi), IShellItem)
            hr = pFileSaveDialog.SetFolder(pShellItem)
            hr = pFileSaveDialog.Show(Me.Handle)
            If (hr = HRESULT.S_OK) Then
                Dim pShellItemResult As IShellItem = Nothing
                hr = pFileSaveDialog.GetResult(pShellItemResult)
                Dim sResult As String = Nothing
                Dim sSBResult As System.Text.StringBuilder = New System.Text.StringBuilder(MAX_PATH)
                hr = pShellItemResult.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, sSBResult)
                If (hr = HRESULT.S_OK) Then
                    sResult = sSBResult.ToString
                End If
            End If
        End If
    End If

    With declarations :

        Public Enum HRESULT As Integer
            S_OK = 0
            S_FALSE = 1
            E_NOINTERFACE = &H80004002
            E_NOTIMPL = &H80004001
            E_FAIL = &H80004005
            E_INVALIDARG = &H80070057
        End Enum
        Enum SIGDN As Integer
            SIGDN_NORMALDISPLAY = &H0
            SIGDN_PARENTRELATIVEPARSING = &H80018001
            SIGDN_DESKTOPABSOLUTEPARSING = &H80028000
            SIGDN_PARENTRELATIVEEDITING = &H80031001
            SIGDN_DESKTOPABSOLUTEEDITING = &H8004C000
            SIGDN_FILESYSPATH = &H80058000
            SIGDN_URL = &H80068000
            SIGDN_PARENTRELATIVEFORADDRESSBAR = &H8007C001
            SIGDN_PARENTRELATIVE = &H80080001
        End Enum
    
        Enum FOS As Integer
            FOS_OVERWRITEPROMPT = &H2
            FOS_STRICTFILETYPES = &H4
            FOS_NOCHANGEDIR = &H8
            FOS_PICKFOLDERS = &H20
            FOS_FORCEFILESYSTEM = &H40
            FOS_ALLNONSTORAGEITEMS = &H80
            FOS_NOVALIDATE = &H100
            FOS_ALLOWMULTISELECT = &H200
            FOS_PATHMUSTEXIST = &H800
            FOS_FILEMUSTEXIST = &H1000
            FOS_CREATEPROMPT = &H2000
            FOS_SHAREAWARE = &H4000
            FOS_NOREADONLYRETURN = &H8000
            FOS_NOTESTFILECREATE = &H10000
            FOS_HIDEMRUPLACES = &H20000
            FOS_HIDEPINNEDPLACES = &H40000
            FOS_NODEREFERENCELINKS = &H100000
            FOS_DONTADDTORECENT = &H2000000
            FOS_FORCESHOWHIDDEN = &H10000000
            FOS_DEFAULTNOMINIMODE = &H20000000
        End Enum
    
        Enum FDE_SHAREVIOLATION_RESPONSE As Integer
            FDESVR_DEFAULT = &H0
            FDESVR_ACCEPT = &H1
            FDESVR_REFUSE = &H2
        End Enum
    
        Enum FDE_OVERWRITE_RESPONSE As Integer
            FDEOR_DEFAULT = &H0
            FDEOR_ACCEPT = &H1
            FDEOR_REFUSE = &H2
        End Enum
    
        <ComImport()>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")>
        Public Interface IShellItem
            Function BindToHandler(ByVal pbc As IntPtr, ByRef bhid As Guid, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetParent(ByRef ppsi As IShellItem) As HRESULT
            Function GetDisplayName(ByVal sigdnName As SIGDN, ByRef ppszName As System.Text.StringBuilder) As HRESULT
            Function GetAttributes(ByVal sfgaoMask As UInteger, ByRef psfgaoAttribs As UInteger) As HRESULT
            Function Compare(ByVal psi As IShellItem, ByVal hint As UInteger, ByRef piOrder As Integer) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("973510DB-7D7F-452B-8975-74A85828D354")>
        Public Interface IFileDialogEvents
            <PreserveSig()>
            Function OnFileOk(ByVal pfd As IFileDialog) As HRESULT
            <PreserveSig()>
            Function OnFolderChanging(ByVal pfd As IFileDialog, ByVal psiFolder As IShellItem) As HRESULT
            Function OnFolderChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnSelectionChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnShareViolation(ByVal pfd As IFileDialog, ByVal psi As IShellItem, ByRef pResponse As FDE_SHAREVIOLATION_RESPONSE) As HRESULT
            Function OnTypeChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnOverwrite(ByVal pfd As IFileDialog, ByVal psi As IShellItem, ByRef pResponse As FDE_OVERWRITE_RESPONSE) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("b4db1657-70d7-485e-8e3e-6fcb5a5c1802")>
        Public Interface IModalWindow
            Function Show(hwndOwner As IntPtr) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("42f85136-db7e-439c-85f1-e4075d135fc8")>
        Public Interface IFileDialog
            Inherits IModalWindow
            <PreserveSig()>
            Overloads Function Show(hwndOwner As IntPtr) As HRESULT
            Function SetFileTypes(ByVal cFileTypes As UInteger) As HRESULT
            Function SetFileTypeIndex(ByVal iFileType As UInteger) As HRESULT
            Function GetFileTypeIndex(ByRef piFileType As UInteger) As HRESULT
            Function Advise(ByVal pfde As IFileDialogEvents, ByRef pdwCookie As UInteger) As HRESULT
            Function Unadvise(ByVal dwCookie As UInteger) As HRESULT
            Function SetOptions(ByVal fos As FOS) As HRESULT
            Function GetOptions(ByRef pfos As FOS) As HRESULT
            Function SetDefaultFolder(ByVal psi As IShellItem) As HRESULT
            Function SetFolder(ByVal psi As IShellItem) As HRESULT
            Function GetFolder(ByRef ppsi As IShellItem) As HRESULT
            Function GetCurrentSelection(ByRef ppsi As IShellItem) As HRESULT
            Function SetFileName(ByVal pszName As String) As HRESULT
            Function GetFileName(ByRef pszName As String) As HRESULT
            Function SetTitle(ByVal pszTitle As String) As HRESULT
            Function SetOkButtonLabel(ByVal pszText As String) As HRESULT
            Function SetFileNameLabel(ByVal pszLabel As String) As HRESULT
            Function GetResult(ByRef ppsi As IShellItem) As HRESULT
            Function AddPlace(ByVal psi As IShellItem, ByVal alignment As Integer) As HRESULT
            Function SetDefaultExtension(ByVal pszDefaultExtension As String) As HRESULT
            Function Close(ByVal hr As Integer) As HRESULT
            Function SetClientGuid(ByRef guid As Guid) As HRESULT
            Function ClearClientData() As HRESULT
            Function SetFilter(ByVal pFilter As IntPtr) As HRESULT
        End Interface
    
        Public Const MAX_PATH = 260
    
        <DllImport("Shell32", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function SHCreateItemFromParsingName(pszPath As String, pbc As IntPtr, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
        End Function


    • Edited by Castorix31 Friday, January 3, 2020 9:12 PM
    • Marked as answer by MRM256 Sunday, January 5, 2020 9:45 PM
    Friday, January 3, 2020 9:11 PM

All replies

  • I am working on a project where I need the ability to see hidden Folders and Files. None of the Open dialog controls have that ability, so I was forced to find a workaround.

    I just tested  (Windows 10) and IFileDialog with FOS_FORCESHOWHIDDEN option (P/Invoke) shows hidden files

    even if the option is not set in Explorer

    Friday, January 3, 2020 6:53 PM
  • Thanks Castorix31 for the alternative. Do you have any sample code on now to invoke the change?


    MRM256

    Friday, January 3, 2020 8:49 PM
  • The test I did =>

    (initial directory set to "e:\toto1" for testing)

    Dim pFileSaveDialog As IFileDialog
    
    Dim hr As HRESULT = HRESULT.E_FAIL
    Dim CLSID_FileOpenDialog As New Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")
    ' Dim CLSID_FileSaveDialog As New Guid("C0B4E2F3-BA21-4773-8DBA-335EC946EB8B")
    Dim FileSaveDialogType As Type = Type.GetTypeFromCLSID(CLSID_FileOpenDialog, True)
    Dim FileSaveDialog As Object = Activator.CreateInstance(FileSaveDialogType)
    pFileSaveDialog = DirectCast(FileSaveDialog, IFileDialog)
    If (pFileSaveDialog IsNot Nothing) Then
        Dim nOptions As FOS = 0
        hr = pFileSaveDialog.GetOptions(nOptions)
        'nOptions = nOptions Or FOS.FOS_PICKFOLDERS
        nOptions = nOptions Or FOS.FOS_FORCESHOWHIDDEN
        hr = pFileSaveDialog.SetOptions(nOptions)
    
        Dim psi As IntPtr = IntPtr.Zero
        Dim GUID_IShellItem As New Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")
        hr = SHCreateItemFromParsingName("e:\toto1", IntPtr.Zero, GUID_IShellItem, psi)
        If (hr = HRESULT.S_OK) Then
            Dim pShellItem As IShellItem = CType(Marshal.GetObjectForIUnknown(psi), IShellItem)
            hr = pFileSaveDialog.SetFolder(pShellItem)
            hr = pFileSaveDialog.Show(Me.Handle)
            If (hr = HRESULT.S_OK) Then
                Dim pShellItemResult As IShellItem = Nothing
                hr = pFileSaveDialog.GetResult(pShellItemResult)
                Dim sResult As String = Nothing
                Dim sSBResult As System.Text.StringBuilder = New System.Text.StringBuilder(MAX_PATH)
                hr = pShellItemResult.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, sSBResult)
                If (hr = HRESULT.S_OK) Then
                    sResult = sSBResult.ToString
                End If
            End If
        End If
    End If

    With declarations :

        Public Enum HRESULT As Integer
            S_OK = 0
            S_FALSE = 1
            E_NOINTERFACE = &H80004002
            E_NOTIMPL = &H80004001
            E_FAIL = &H80004005
            E_INVALIDARG = &H80070057
        End Enum
        Enum SIGDN As Integer
            SIGDN_NORMALDISPLAY = &H0
            SIGDN_PARENTRELATIVEPARSING = &H80018001
            SIGDN_DESKTOPABSOLUTEPARSING = &H80028000
            SIGDN_PARENTRELATIVEEDITING = &H80031001
            SIGDN_DESKTOPABSOLUTEEDITING = &H8004C000
            SIGDN_FILESYSPATH = &H80058000
            SIGDN_URL = &H80068000
            SIGDN_PARENTRELATIVEFORADDRESSBAR = &H8007C001
            SIGDN_PARENTRELATIVE = &H80080001
        End Enum
    
        Enum FOS As Integer
            FOS_OVERWRITEPROMPT = &H2
            FOS_STRICTFILETYPES = &H4
            FOS_NOCHANGEDIR = &H8
            FOS_PICKFOLDERS = &H20
            FOS_FORCEFILESYSTEM = &H40
            FOS_ALLNONSTORAGEITEMS = &H80
            FOS_NOVALIDATE = &H100
            FOS_ALLOWMULTISELECT = &H200
            FOS_PATHMUSTEXIST = &H800
            FOS_FILEMUSTEXIST = &H1000
            FOS_CREATEPROMPT = &H2000
            FOS_SHAREAWARE = &H4000
            FOS_NOREADONLYRETURN = &H8000
            FOS_NOTESTFILECREATE = &H10000
            FOS_HIDEMRUPLACES = &H20000
            FOS_HIDEPINNEDPLACES = &H40000
            FOS_NODEREFERENCELINKS = &H100000
            FOS_DONTADDTORECENT = &H2000000
            FOS_FORCESHOWHIDDEN = &H10000000
            FOS_DEFAULTNOMINIMODE = &H20000000
        End Enum
    
        Enum FDE_SHAREVIOLATION_RESPONSE As Integer
            FDESVR_DEFAULT = &H0
            FDESVR_ACCEPT = &H1
            FDESVR_REFUSE = &H2
        End Enum
    
        Enum FDE_OVERWRITE_RESPONSE As Integer
            FDEOR_DEFAULT = &H0
            FDEOR_ACCEPT = &H1
            FDEOR_REFUSE = &H2
        End Enum
    
        <ComImport()>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")>
        Public Interface IShellItem
            Function BindToHandler(ByVal pbc As IntPtr, ByRef bhid As Guid, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetParent(ByRef ppsi As IShellItem) As HRESULT
            Function GetDisplayName(ByVal sigdnName As SIGDN, ByRef ppszName As System.Text.StringBuilder) As HRESULT
            Function GetAttributes(ByVal sfgaoMask As UInteger, ByRef psfgaoAttribs As UInteger) As HRESULT
            Function Compare(ByVal psi As IShellItem, ByVal hint As UInteger, ByRef piOrder As Integer) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("973510DB-7D7F-452B-8975-74A85828D354")>
        Public Interface IFileDialogEvents
            <PreserveSig()>
            Function OnFileOk(ByVal pfd As IFileDialog) As HRESULT
            <PreserveSig()>
            Function OnFolderChanging(ByVal pfd As IFileDialog, ByVal psiFolder As IShellItem) As HRESULT
            Function OnFolderChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnSelectionChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnShareViolation(ByVal pfd As IFileDialog, ByVal psi As IShellItem, ByRef pResponse As FDE_SHAREVIOLATION_RESPONSE) As HRESULT
            Function OnTypeChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnOverwrite(ByVal pfd As IFileDialog, ByVal psi As IShellItem, ByRef pResponse As FDE_OVERWRITE_RESPONSE) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("b4db1657-70d7-485e-8e3e-6fcb5a5c1802")>
        Public Interface IModalWindow
            Function Show(hwndOwner As IntPtr) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("42f85136-db7e-439c-85f1-e4075d135fc8")>
        Public Interface IFileDialog
            Inherits IModalWindow
            <PreserveSig()>
            Overloads Function Show(hwndOwner As IntPtr) As HRESULT
            Function SetFileTypes(ByVal cFileTypes As UInteger) As HRESULT
            Function SetFileTypeIndex(ByVal iFileType As UInteger) As HRESULT
            Function GetFileTypeIndex(ByRef piFileType As UInteger) As HRESULT
            Function Advise(ByVal pfde As IFileDialogEvents, ByRef pdwCookie As UInteger) As HRESULT
            Function Unadvise(ByVal dwCookie As UInteger) As HRESULT
            Function SetOptions(ByVal fos As FOS) As HRESULT
            Function GetOptions(ByRef pfos As FOS) As HRESULT
            Function SetDefaultFolder(ByVal psi As IShellItem) As HRESULT
            Function SetFolder(ByVal psi As IShellItem) As HRESULT
            Function GetFolder(ByRef ppsi As IShellItem) As HRESULT
            Function GetCurrentSelection(ByRef ppsi As IShellItem) As HRESULT
            Function SetFileName(ByVal pszName As String) As HRESULT
            Function GetFileName(ByRef pszName As String) As HRESULT
            Function SetTitle(ByVal pszTitle As String) As HRESULT
            Function SetOkButtonLabel(ByVal pszText As String) As HRESULT
            Function SetFileNameLabel(ByVal pszLabel As String) As HRESULT
            Function GetResult(ByRef ppsi As IShellItem) As HRESULT
            Function AddPlace(ByVal psi As IShellItem, ByVal alignment As Integer) As HRESULT
            Function SetDefaultExtension(ByVal pszDefaultExtension As String) As HRESULT
            Function Close(ByVal hr As Integer) As HRESULT
            Function SetClientGuid(ByRef guid As Guid) As HRESULT
            Function ClearClientData() As HRESULT
            Function SetFilter(ByVal pFilter As IntPtr) As HRESULT
        End Interface
    
        Public Const MAX_PATH = 260
    
        <DllImport("Shell32", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function SHCreateItemFromParsingName(pszPath As String, pbc As IntPtr, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
        End Function


    • Edited by Castorix31 Friday, January 3, 2020 9:12 PM
    • Marked as answer by MRM256 Sunday, January 5, 2020 9:45 PM
    Friday, January 3, 2020 9:11 PM
  • Good Lord!

    That is some test! You seem to know your way around the nuts & bolts of VB.

    You are referencing a bunch of stuff I stay away from Guid, <ComImport>, etc.. Is all this inside the Form Designer's code? 

    Where is this stuff kept?

    I like the idea of using the OpenFileDialog control and having the ability to set it to show hidden folders and files.

    Thanks,


    MRM256

    Friday, January 3, 2020 10:14 PM
  • You are referencing a bunch of stuff I stay away from Guid, <ComImport>, etc.. Is all this inside the Form Designer's code? 

    The declarations are put in your main class, like you did for SHGetFileInfo, etc...

    I just converted them from C++ headers (.h)

    Saturday, January 4, 2020 12:05 AM
  • Castorix31,

    I am going to test your code today after I get back. 

    Where did you find that C example? What search phrase did you use?

    I tried many variations for showing hidden folders/files using the Open File Dialog control and didn't get anything back that I could use.

    Thanks,


    MRM256

    Saturday, January 4, 2020 3:18 PM
  • I'm afraid you will have to walk me through it step by step.

    I created a new Windows 10 project to test code. Right now it is a blank project. Just a blank form.

    In other words: I need to see it work.

    Thanks,


    MRM256


    • Edited by MRM256 Saturday, January 4, 2020 8:48 PM Clarification
    Saturday, January 4, 2020 6:57 PM
  • Just add a button and the code in Click event to test it

    Declarations in your class (like in your sample you posted first)

    Sunday, January 5, 2020 9:13 AM
  • Just add a button and the code in Click event to test it

    Declarations in your class (like in your sample you posted first)

    Here I think this is working. It gives the path as

    sResult

    to the file you select in the dialog. You need to set the seed path  ie set e:\toto to a folder on your system.

    I am not sure what files or folders are hidden or what is next to do. Is the dialog showing the hidden files and icons? So now you can get the icons?

    The example makes the controls. Just cut and paste the code to an empty form. Change the form name as required.

    Set a break on sresult = and run. Click the button and select a file from the dialog. Select ok and look at the result.

    Imports System.Runtime.InteropServices
    
    Public Class Form7
        Private WithEvents Button1 As New Button With {.Parent = Me, .Text = "Files...", .Location = New Point(20, 20)}
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim pFileSaveDialog As IFileDialog
    
            Dim hr As HRESULT = HRESULT.E_FAIL
            Dim CLSID_FileOpenDialog As New Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")
            ' Dim CLSID_FileSaveDialog As New Guid("C0B4E2F3-BA21-4773-8DBA-335EC946EB8B")
            Dim FileSaveDialogType As Type = Type.GetTypeFromCLSID(CLSID_FileOpenDialog, True)
            Dim FileSaveDialog As Object = Activator.CreateInstance(FileSaveDialogType)
            pFileSaveDialog = DirectCast(FileSaveDialog, IFileDialog)
    
    
            If (pFileSaveDialog IsNot Nothing) Then
                Dim nOptions As FOS = 0
                hr = pFileSaveDialog.GetOptions(nOptions)
                'nOptions = nOptions Or FOS.FOS_PICKFOLDERS
                nOptions = nOptions Or FOS.FOS_FORCESHOWHIDDEN
                hr = pFileSaveDialog.SetOptions(nOptions)
    
                Dim psi As IntPtr = IntPtr.Zero
                Dim GUID_IShellItem As New Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")
                'hr = SHCreateItemFromParsingName("e:\toto1", IntPtr.Zero, GUID_IShellItem, psi)
                hr = SHCreateItemFromParsingName("c:\bitmaps", IntPtr.Zero, GUID_IShellItem, psi)
    
                If (hr = HRESULT.S_OK) Then
                    Dim pShellItem As IShellItem = CType(Marshal.GetObjectForIUnknown(psi), IShellItem)
                    hr = pFileSaveDialog.SetFolder(pShellItem)
                    hr = pFileSaveDialog.Show(Me.Handle)
                    If (hr = HRESULT.S_OK) Then
                        Dim pShellItemResult As IShellItem = Nothing
                        hr = pFileSaveDialog.GetResult(pShellItemResult)
                        Dim sResult As String = Nothing
                        Dim sSBResult As System.Text.StringBuilder = New System.Text.StringBuilder(MAX_PATH)
                        hr = pShellItemResult.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, sSBResult)
                        If (hr = HRESULT.S_OK) Then
                            sResult = sSBResult.ToString
                        End If
                    End If
                End If
            End If
        End Sub
    
        Public Enum HRESULT As Integer
            S_OK = 0
            S_FALSE = 1
            E_NOINTERFACE = &H80004002
            E_NOTIMPL = &H80004001
            E_FAIL = &H80004005
            E_INVALIDARG = &H80070057
        End Enum
        Enum SIGDN As Integer
            SIGDN_NORMALDISPLAY = &H0
            SIGDN_PARENTRELATIVEPARSING = &H80018001
            SIGDN_DESKTOPABSOLUTEPARSING = &H80028000
            SIGDN_PARENTRELATIVEEDITING = &H80031001
            SIGDN_DESKTOPABSOLUTEEDITING = &H8004C000
            SIGDN_FILESYSPATH = &H80058000
            SIGDN_URL = &H80068000
            SIGDN_PARENTRELATIVEFORADDRESSBAR = &H8007C001
            SIGDN_PARENTRELATIVE = &H80080001
        End Enum
    
        Enum FOS As Integer
            FOS_OVERWRITEPROMPT = &H2
            FOS_STRICTFILETYPES = &H4
            FOS_NOCHANGEDIR = &H8
            FOS_PICKFOLDERS = &H20
            FOS_FORCEFILESYSTEM = &H40
            FOS_ALLNONSTORAGEITEMS = &H80
            FOS_NOVALIDATE = &H100
            FOS_ALLOWMULTISELECT = &H200
            FOS_PATHMUSTEXIST = &H800
            FOS_FILEMUSTEXIST = &H1000
            FOS_CREATEPROMPT = &H2000
            FOS_SHAREAWARE = &H4000
            FOS_NOREADONLYRETURN = &H8000
            FOS_NOTESTFILECREATE = &H10000
            FOS_HIDEMRUPLACES = &H20000
            FOS_HIDEPINNEDPLACES = &H40000
            FOS_NODEREFERENCELINKS = &H100000
            FOS_DONTADDTORECENT = &H2000000
            FOS_FORCESHOWHIDDEN = &H10000000
            FOS_DEFAULTNOMINIMODE = &H20000000
        End Enum
    
        Enum FDE_SHAREVIOLATION_RESPONSE As Integer
            FDESVR_DEFAULT = &H0
            FDESVR_ACCEPT = &H1
            FDESVR_REFUSE = &H2
        End Enum
    
        Enum FDE_OVERWRITE_RESPONSE As Integer
            FDEOR_DEFAULT = &H0
            FDEOR_ACCEPT = &H1
            FDEOR_REFUSE = &H2
        End Enum
    
        <ComImport()>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")>
        Public Interface IShellItem
            Function BindToHandler(ByVal pbc As IntPtr, ByRef bhid As Guid, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
            Function GetParent(ByRef ppsi As IShellItem) As HRESULT
            Function GetDisplayName(ByVal sigdnName As SIGDN, ByRef ppszName As System.Text.StringBuilder) As HRESULT
            Function GetAttributes(ByVal sfgaoMask As UInteger, ByRef psfgaoAttribs As UInteger) As HRESULT
            Function Compare(ByVal psi As IShellItem, ByVal hint As UInteger, ByRef piOrder As Integer) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("973510DB-7D7F-452B-8975-74A85828D354")>
        Public Interface IFileDialogEvents
            <PreserveSig()>
            Function OnFileOk(ByVal pfd As IFileDialog) As HRESULT
            <PreserveSig()>
            Function OnFolderChanging(ByVal pfd As IFileDialog, ByVal psiFolder As IShellItem) As HRESULT
            Function OnFolderChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnSelectionChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnShareViolation(ByVal pfd As IFileDialog, ByVal psi As IShellItem, ByRef pResponse As FDE_SHAREVIOLATION_RESPONSE) As HRESULT
            Function OnTypeChange(ByVal pfd As IFileDialog) As HRESULT
            Function OnOverwrite(ByVal pfd As IFileDialog, ByVal psi As IShellItem, ByRef pResponse As FDE_OVERWRITE_RESPONSE) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("b4db1657-70d7-485e-8e3e-6fcb5a5c1802")>
        Public Interface IModalWindow
            Function Show(hwndOwner As IntPtr) As HRESULT
        End Interface
    
        <ComImport>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        <Guid("42f85136-db7e-439c-85f1-e4075d135fc8")>
        Public Interface IFileDialog
            Inherits IModalWindow
            <PreserveSig()>
            Overloads Function Show(hwndOwner As IntPtr) As HRESULT
            Function SetFileTypes(ByVal cFileTypes As UInteger) As HRESULT
            Function SetFileTypeIndex(ByVal iFileType As UInteger) As HRESULT
            Function GetFileTypeIndex(ByRef piFileType As UInteger) As HRESULT
            Function Advise(ByVal pfde As IFileDialogEvents, ByRef pdwCookie As UInteger) As HRESULT
            Function Unadvise(ByVal dwCookie As UInteger) As HRESULT
            Function SetOptions(ByVal fos As FOS) As HRESULT
            Function GetOptions(ByRef pfos As FOS) As HRESULT
            Function SetDefaultFolder(ByVal psi As IShellItem) As HRESULT
            Function SetFolder(ByVal psi As IShellItem) As HRESULT
            Function GetFolder(ByRef ppsi As IShellItem) As HRESULT
            Function GetCurrentSelection(ByRef ppsi As IShellItem) As HRESULT
            Function SetFileName(ByVal pszName As String) As HRESULT
            Function GetFileName(ByRef pszName As String) As HRESULT
            Function SetTitle(ByVal pszTitle As String) As HRESULT
            Function SetOkButtonLabel(ByVal pszText As String) As HRESULT
            Function SetFileNameLabel(ByVal pszLabel As String) As HRESULT
            Function GetResult(ByRef ppsi As IShellItem) As HRESULT
            Function AddPlace(ByVal psi As IShellItem, ByVal alignment As Integer) As HRESULT
            Function SetDefaultExtension(ByVal pszDefaultExtension As String) As HRESULT
            Function Close(ByVal hr As Integer) As HRESULT
            Function SetClientGuid(ByRef guid As Guid) As HRESULT
            Function ClearClientData() As HRESULT
            Function SetFilter(ByVal pFilter As IntPtr) As HRESULT
        End Interface
    
        Public Const MAX_PATH As Integer = 260
    
        <DllImport("Shell32", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function SHCreateItemFromParsingName(pszPath As String, pbc As IntPtr, ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
        End Function
    End Class

    Sunday, January 5, 2020 12:12 PM

  • I am not sure what files or folders are hidden or what is next to do. 


    To test on Windows 10,
    I hid a file in Explorer,
    I unchecked "Hidden item" (like in Show Hidden Files on Windows 8 and 10)
    And the file is displayed by using the flag FOS.FOS_FORCESHOWHIDDEN (not displayed without the flag)
    Sunday, January 5, 2020 12:32 PM
  • Hi tommytwotrain,

    You example works. The OpenFileDialog functioned where I could see the C:\Users\Default|AppData folder. As you know - The AppData folder is hidden. 

    What I could not do was find the *.EML files. According to Google, they are suppose to be on C:\Users\<username>\AppData\Local\Packages\

    For some reason I can't see the Packages folder. Does something need to be adjusted?

    I need to see the *.EML hidden files before I can call this question closed.

    Thanks, 


    MRM256


    • Edited by MRM256 Sunday, January 5, 2020 4:33 PM Clarification
    Sunday, January 5, 2020 4:18 PM
  • Hi tommytwotrain,

    You example works. The OpenFileDialog functioned where I could see the C:\Users\Default|AppData folder. As you know - The AppData folder is hidden. 

    What I could not do was find the *.EML files. According to Google, they are suppose to be on C:\Users\<username>\AppData\Local\Packages\

    For some reason I can't see the Packages folder. Does something need to be adjusted?

    I need to see the *.EML hidden files before I can call this question closed.

    Thanks, 


    MRM256


    MRM,

    Its Castor's code example I just put it in a form. :)

    Do you see anything with windows file explorer showing hidden files at that location?

    btw you look in the <username> folder not the <default> just to be sure.

    In win10 I have the packages folder and sub folders but I cant find any .eml files on the system.

    Have you installed the EML making app and run it on that system?

    I dont know what it is really. I have old Outlook it may not use .eml.



    Sunday, January 5, 2020 6:28 PM
  • I need to clarify a few things.

    1. I am using the Windows 10 Mail App and Google indicated where the EML files are stored. No EML making app.

    2. You can't look at the Header information in the Win10 mail app. Therefore, I need to be able to read the entire email so I can parse it. 

    3. I am making this so the user does not have to change settings in Explorer. Last time I did; I had to restore my PC.

    In a nut shell: Select an email file and parse it.

    Thanks,


    MRM256

    Sunday, January 5, 2020 7:37 PM
  • if your email provider is using IMAP then there may not be local storage of messages for that account.
    Sunday, January 5, 2020 8:02 PM
  • Thanks.

    I went and accepted Castorix31 answer as that one works. It showed the hidden folders.

    Now I need to figure out the .EML part, which is going to be another question on another forum.

    Thank you everyone for your help.


    MRM256

    Sunday, January 5, 2020 9:48 PM