Question Change the Windows Explorer View Mode to "Details" on an external Explorer task

Remala

New member
Joined
Jun 18, 2020
Messages
1
Programming Experience
10+
Hi there,

My application gets the file list from the actual folder Windows Explorer is pointed to. It is working well.
I just need to programmatically change the Windows Explorer View Mode to "Details", on that external Windows Explorer task.
I have already searched VB forums and found nothing about. Thanks for any help.
This is my code:
VB.NET:
Imports System.IO
Imports System.IO.FileAttributes
Imports System.IO.File
Imports System.IO.Directory
Imports Shell32               ' for ShellFolderView
Imports SHDocVw               ' for IShellWindows
Imports System.Text.RegularExpressions

Public Class frmViewMode

    Private Sub ViewMode_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim strActiveExplorerFolder As String

        strActiveExplorerFolder = GetExplorerPath()              ' Actual folder Windows Explorer is pointed to
        If strActiveExplorerFolder <> "" Then LoadFiles(strActiveExplorerFolder)

        ' Here I need some code to change the Windows Explorer View Mode to "Details",
        ' no matters the actual view mode setting.

        End If

    End Sub

    Private Function GetExplorerPath() As String
        Dim exShell As New Shell
        Dim expPath As String
        For Each w As ShellBrowserWindow In DirectCast(exShell.Windows, IShellWindows)
            If TryCast(w.Document, IShellFolderViewDual) IsNot Nothing Then                     ' try to cast to an explorer folder
                expPath = DirectCast(w.Document, IShellFolderViewDual).FocusedItem.Path
                Return Path.GetDirectoryName(expPath)                                           ' remove GetDirectoryName method to return selected file rather than folder
            ElseIf TryCast(w.Document, ShellFolderView) IsNot Nothing Then
                expPath = DirectCast(w.Document, ShellFolderView).FocusedItem.Path
                Return Path.GetDirectoryName(expPath)
            End If
        Next
        Return ""
    End Function

    Private Sub LoadFiles(ByVal strFolder as string)

        ' my code here to get and work with the file list

    End Sub

End Class
 
Not sure why you cast as IShellFolderViewDual, ShellFolderView already implements latest version IShellFolderViewDual3. Anyway, when you cast to the ShellFolderView you can set CurrentViewMode to a value in FolderViewMode enumeration, found it declared in a post here: How to access and direct the "shell" in Windows?
 

Latest posts

Back
Top