Read/Write 'Extended' file properties (C#)

后端 未结 10 2515
我在风中等你
我在风中等你 2020-11-22 02:54

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. An

10条回答
  •  我在风中等你
    2020-11-22 03:41

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

    Note, you have to add a reference to Microsoft Shell Controls and Automation from the COM tab of the References dialog.

    public static void Main(string[] args)
    {
        List arrHeaders = new List();
    
        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(
                  $"{i}\t{arrHeaders[i]}: {objFolder.GetDetailsOf(item, i)}");
            }
        }
    }
    

提交回复
热议问题