Question

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.

Was it helpful?

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.

OTHER TIPS

Is there a cleaner, faster way to do this?

Something like this should work:

Imports System.IO

    Dim test() As FileSystemInfo = New DirectoryInfo("MyDirectoryPath").GetFileSystemInfos("MyImageFile")
    'MyImageFile is actually a search pattern string.  the result is an array 
    'containing info on every file in the folder that matches the search pattern.
    'If the pattern is unique then only one file will be returned and using
    'the FullName property will return the full path to the file.
    test(0).FullName()
    'Or just the Name property to return just the file name
    test(0).Name()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top