Henry Lasher

Henry Lasher

  • NA
  • 24
  • 668

Getting null when reading extended tags on a TIF file.

May 8 2019 8:50 PM
  1. string tag = GetExtendedFileAttribute(@"file path goes here""Tags");   
  2. public static string GetExtendedFileAttribute(string filePath, string propertyName)  
  3. {  
  4. string retValue = null;  
  5. Type shellAppType = Type.GetTypeFromProgID("Shell.Application");  
  6. object shell = Activator.CreateInstance(shellAppType);  
  7. Shell32.Folder folder = (Shell32.Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { @"C:\Windows\System32" });  
  8. int? foundIdx = null;  
  9. for (int i = 0; i < short.MaxValue; i++)  
  10. {  
  11. string header = folder.GetDetailsOf(null, i);  
  12. Console.WriteLine(header);  
  13. if (header == propertyName)  
  14. {  
  15. foundIdx = i;  
  16. break;  
  17. }  
  18. }  
  19. if (foundIdx.HasValue)  
  20. {  
  21. foreach (FolderItem2 item in folder.Items())  
  22. {  
  23. if (item.Name.ToUpper() == System.IO.Path.GetFileName(filePath).ToUpper())  
  24. {  
  25. retValue = folder.GetDetailsOf(item, foundIdx.GetValueOrDefault());  
  26. break;  
  27. }  
  28. }  
  29. }  
  30. return retValue;  
  31. }  

Answers (1)