Some files has Summary tab in their Properties, This tab include information like Title, Author, Comments. Is there any way in C# to read the Comments of the file. I have to read only comments from image files like jpg.
-
3look here [http://stackoverflow.com/questions/220097/read-write-extended-file-properties-c](http://stackoverflow.com/questions/220097/read-write-extended-file-properties-c) – thepoosh May 02 '12 at 06:16
2 Answers
The comments and other answer are good places to search. Here is some complete code to help you out. Ensure you reference shell32.dll
first and the namespace Shell32
. I've done this in LINQPad so it's a touch different.
Pick a test file and folder:
var folder = "...";
var file = "...";
Get the Shell objects:
// For our LINQPad Users
// var shellType = Type.GetTypeFromProgID("Shell.Application");
// dynamic app = Activator.CreateInstance(shellType);
Shell32.Shell app = new Shell32.Shell();
Get the folder and file objects:
var folderObj = app.NameSpace(folder);
var filesObj = folderObj.Items();
Find the possible headers:
var headers = new Dictionary<string, int>();
for( int i = 0; i < short.MaxValue; i++ )
{
string header = folderObj.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
if (!headers.ContainsKey(header)) headers.Add(header, i);
}
You can print these out if you like - that's all possible headers available in that directory. Let's use the header 'Comments' as an example:
var testFile = filesObj.Item(file);
Console.WriteLine("{0} -> {1}", testFile.Name, folderObj.GetDetailsOf(testFile, headers["Comments"]));
Modify as needed!

- 15,390
- 3
- 42
- 52
-
Almost equal to my beloved VBA background!!!! `Set sh = CreateObject("shell.application")` – Marcelo Scofano Diniz Nov 14 '20 at 15:13
The shell (shell32.dll) will help you to solve this poroblem. I recently found this great article on the MSDN (http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/94430444-283b-4a0e-9ca5-7375c8420622).
There is also a codeproject on reading ID3 tags.

- 1,953
- 2
- 21
- 45