0

I want to get the "Material Name" file property value: enter image description here

I tried a lot of solutions, like looping all extended file properties using this solution: Read/Write 'Extended' file properties (C#) but the "Material Name" is not there.

sorry I found now the "Material Name" property After changing the code of the above example to:

 public static string GetExtendedFileProperty(string filePath, string propertyName)
    {
        string value = string.Empty;
        string baseFolder = Path.GetDirectoryName(filePath);
        string fileName = Path.GetFileName(filePath);

        //Method to load and execute the Shell object for Windows server 8 environment otherwise you get "Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell32.Shell'"
        Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
        Object shell = Activator.CreateInstance(shellAppType);
        Shell32.Folder shellFolder = (Shell32.Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { baseFolder });

        //Parsename will find the specific file I'm looking for in the Shell32.Folder object
        Shell32.FolderItem folderitem = shellFolder.ParseName(fileName);
        if (folderitem != null)
        {
            for (int i = 0; i < short.MaxValue; i++)
            {
                //Get the property name for property index i
                string property = shellFolder.GetDetailsOf(null, i);

                if (String.IsNullOrEmpty(property)) continue;

                //Skip to next property if this is not the specified property
                if (property != propertyName) continue;

                //Read value of property
                value = shellFolder.GetDetailsOf(folderitem, i);

                Console.WriteLine("{0}\t{1}",property,value);

                break;
            }
        }
        //returns string.Empty if no value was found for the specified property
        return value;
    }

The "Material Name" property is there, but shellFolder.GetDetailsOf(folderitem, i) retrieves no value...

Ezra
  • 161
  • 1
  • 11
  • See following : https://stackoverflow.com/questions/39413320/showing-custom-file-properties-in-the-windows-explorer-file-hover-tooltip – jdweng Mar 06 '19 at 10:09
  • did you tried the second answer of the question that you linked? That seems to work. If this still not work then you could try to use the windows api code pack: https://www.nuget.org/packages/winapicp/ - an example how to extract the data with the api is here: https://dzone.com/articles/extracting-file-metadata-c-and – Marco Sadowski Mar 06 '19 at 10:11
  • ah in the question is also a answer which use the windows api code pack: https://stackoverflow.com/a/37986932/9290012 – Marco Sadowski Mar 06 '19 at 10:32
  • @jdweng this is an example for custom properties – Ezra Mar 06 '19 at 12:51
  • @Marco Sadowski I use the Windows Codepack already for other properties, but I can not find there this property, I also updated my questions, pls see... – Ezra Mar 06 '19 at 13:04

0 Answers0