views:

7498

answers:

5

Hi I'm trying to find out how to read/write to the extended file properties in C# e.g. Comment, Bit Rate, Date Accessed, Category etc that you can see in Windows explorer. Any ideas how to do this? EDIT: I'll mainly be reading/writing to video files (AVI/DIVX/...)

+6  A: 

There's a CodeProject article for an ID3 reader. And a thread at kixtart.org that has more information for other properties. Basically, you need to call the GetDetailsOf() method on the folder shell object for shell32.dll.

Mark Cidade
Thanks, I should be able to pull together what I need from this
David Hayes
+1  A: 

I'm not sure what types of files you are trying to write the properties for but taglib-sharp is an excellent open source tagging library that wraps up all this functionality nicely. It has a lot of built in support for most of the popular media file types but also allows you to do more advanced tagging with pretty much any file.

EDIT: I've updated the link to taglib sharp. The old link no longer worked.

mockedobject
This looks very interesting, I'll mainly be looking at video files (AVI, DIVX etc). Thanks for the pointer
David Hayes
The taglib-sharp link seems to be dead :-(- which is weird as the wiki at ... http://developer.novell.com/wiki/index.php/TagLib_Sharp:_Examples ... points to that URL
SteveC
Thanks, SteveC, at the time I posted this both links were valid and I wasn't sure which was the official place to go, looks like novell is the right site to go to for this lib now.
mockedobject
+4  A: 

Hi, this sample in VB.Net reads all extended properties:

Sub Main()
        Dim arrHeaders(35)

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

        objFolder = shell.NameSpace("C:\tmp")

        For i = 0 To 34
            arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
        Next
        For Each strFileName In objfolder.Items
            For i = 0 To 34
                Console.WriteLine(i & vbTab & arrHeaders(i) & ": " & objfolder.GetDetailsOf(strFileName, i))
            Next
        Next

    End Sub

You have to add a reference to Microsoft Shell Controls and Automation from the COM tab of the Refences dialog.

Regards, divo

0xA3
Worth noting that on Windows 7 (at least) you can increase the size of arrHeaders to just over 280 and get back plenty of additional meta-data. I found this out when I was looking for a way to get meta-data from a WTV file (Windows 7 Media Center recorded television show).
Richard
+4  A: 

For those of not crazy about VB, here it is in c#:

    public static void Main(string[] args)
    {
        List<string> arrHeaders = new List<string>();

        Shell32.Shell shell = new Shell32.Shell();
        Shell32.Folder objFolder;

        objFolder = shell.NameSpace(@"C:\temp\testprop");

        for( int i = 0; i < short.MaxValue; i++ )
        {
            string header = objFolder.GetDetailsOf(null, i);
            if (String.IsNullOrEmpty(header))
                break;
            arrHeaders.Add(header);
        }

        foreach(Shell32.FolderItem2 item in objFolder.Items())
        {
            for (int i = 0; i < arrHeaders.Count; i++)
            {
                Console.WriteLine("{0}\t{1}: {2}", i, arrHeaders[i], objFolder.GetDetailsOf(item, i));
            }
        }
    }
csharptest.net
how would one set one of these values? for e.g. Author or publisher for a .txt file. I am on win 7 and used this and it does show a blank author and publisher and 282 other properties
Vaibhav Garg
@Vainbhav - You can't set these.
csharptest.net
+2  A: 

Thank you guys for this thread! It helped me when I wanted to figure out an exe's file version. However, I needed to figure out the last bit myself of what is called Extended Properties.

If you open properties of an exe (or dll) file in Windows Explorer, you get a Version tab, and a view of Extended Properties of that file. I wanted to access one of those values.

The solution to this is the property indexer FolderItem.ExtendedProperty and if you drop all spaces in the property's name, you'll get the value. E.g. File Version goes FileVersion, and there you have it.

Hope this helps anyone else, just thought I'd add this info to this thread. Cheers!

JERKER