.netvb.netsyntaxfile-attributesshell32.dll

.net GetDetailsOf shell32.folderitem from string


I am trying to get the resolution of an image or video file using GetDetailsOf in vb.net but I do not understand how to load a file into shell32.folderitem so I am doing it a very roundabout way.

    OpenFileDialog1.ShowDialog()
    Dim fi As New FileInfo(OpenFileDialog1.FileName)

    Dim shell As New Shell32.Shell
    Dim objFolder As Shell32.Folder

    objFolder = shell.NameSpace(fi.DirectoryName)
    For i As Integer = 0 To objFolder.Items.Count - 1
        If objFolder.Items(i).name = fi.Name Then

            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 31))
            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 282))
            Console.WriteLine(objFolder.GetDetailsOf(objFolder.Items(i), 280))
        End If
    Next

I am just looping through the folder until I find a match for my file. Is there a cleaner, faster way to do this? I just need to have a shell32.FolderItem from the full filename.

Also, can I rely on Detail 31 to always be resolution and 280/282 to be frame height/frame width? How can I know whether or not they will retrieve the same details on other computers without having to test it on a bunch of other computers?

Thanks.


Solution

  •     Dim fi As New FileInfo(fileName)
        Dim shl As Shell32.Shell = New Shell32.Shell
        Dim dir As Shell32.Folder = shl.[NameSpace](fi.DirectoryName)
        Dim itm As Shell32.FolderItem = dir.Items().Item(fi.Name)
        Dim itm2 As Shell32.ShellFolderItem = DirectCast(itm, Shell32.ShellFolderItem)
    
    
        Dim str As String = dir.GetDetailsOf(itm2, 31)
    

    This got it working without searching for the file. 31 returns image dimensions for me. DirectoryInfo does not have all the metadata that shell32 "getdetailsof" has.