Reputation: 642
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.
Upvotes: 5
Views: 3250
Reputation: 15618
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!
Upvotes: 6
Reputation: 1983
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.
Upvotes: 1