我尝试了很多解决方案,例如使用此解决方案循环所有扩展文件属性: Read/Write 'Extended' file properties (C#) 但是“材料名称”不存在。
抱歉,在将以上示例的代码更改为:
后,我现在找到了“材料名称”属性。 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;
}
“材料名称”属性在那里,但是shellFolder.GetDetailsOf(folderitem,i)没有获取任何值...