Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a comment of the file

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.

like image 813
PsCraft Avatar asked May 02 '12 06:05

PsCraft


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!

like image 114
yamen Avatar answered Oct 28 '22 11:10

yamen


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.

like image 45
HW90 Avatar answered Oct 28 '22 09:10

HW90