2

I would like to read/write the window information file (extended file properties) using c#

The one found by doing the following: In window explorer right click => properties => Summary tab. I want mainly to have access to the properties:

  • Title
  • Category
  • Revision Number

For office document I can use the following (using Office.Interop) or using DSOFile

    private static string GetExcelWorkbookPropertyValue(_Workbook workbook, string propertyName)
    {
        DocumentProperties builtInProperties = (DocumentProperties)workbook.BuiltinDocumentProperties;
        string value = builtInProperties.Cast<DocumentProperty>().First(x => x.Name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase)).Value;
        return value ?? "";
    }

But what i would like is a more general solution that will work with all files.

Could someone help?

Question additional information you can also read the properties Title and Category by using Shell32

        Shell32.Shell shell = new Shell32.Shell();
        //set the namespace to file path
        Shell32.Folder folder = shell.NameSpace(Path.GetDirectoryName(file));
        //get ahandle to the file
        Shell32.FolderItem folderItem = folder.ParseName(Path.GetFileName(file));
        //did we get a handle ?
        if (folderItem != null)
        {
            for (int i = 0; i < 100; i++)
            {
                string s = folder.GetDetailsOf(folderItem, i);
                System.Diagnostics.Debug.WriteLine(s);
            }
        }

However I still write the properity Revision Number, however it's look like Revision number is an office document property and cannot be written (I guess it will break the tracking process of office).

What does not make sense is that I can modify it using window explorer and the property is also visible for non-office documents... I'm struggling to understand that.

Guillaume
  • 1,176
  • 2
  • 11
  • 27
  • possible duplicate of [Read/Write 'Extended' file properties (C#)](http://stackoverflow.com/questions/220097/read-write-extended-file-properties-c) – Alex K. Dec 05 '11 at 11:21
  • 1
    @Alex K: With you reference I can read the properties Title and Category but still can read Revision Number neither write all of them – Guillaume Dec 05 '11 at 11:48
  • Exact Duplicate: http://stackoverflow.com/questions/220097/read-write-extended-file-properties-c , http://stackoverflow.com/questions/5337683/how-to-set-extended-file-properties – Rafael Herscovici Mar 13 '12 at 19:55
  • 1
    @Dementic these posts allow me to read properties and it's true that my question reflect what has been written in these posts, but my end goal is to write the revision number on the document and it's look like they do not provide an answer to that. I change the text to Write file extended porperties. If you have a better wording please fill free to change/submit it. – Guillaume Mar 14 '12 at 11:55
  • @Guillaume - this might also help http://support.microsoft.com/kb/224351 – Rafael Herscovici Mar 14 '12 at 12:07
  • 1
    @Dementic: I read both posts, and try various them, to no avail. dsofile allow you to write a bunch of properties (eg title, commant ...) but not the revisioNumber. Morever dsofile is oriented on OLE document properties, I would like a more general solution, shell32 offer me that, but I can only found a way to read the properties). I already found a workaround and I am happy to live with it, I'm just wondering if writing the revision number on all type of files is possible. if you think the question is stupid or think someone already answer that, I'll delete it. – Guillaume Mar 14 '12 at 12:45

1 Answers1

1

This information is stored in properties. Here are some of the standard properties. I'm not sure if the .NET Framework provides a wrapper around these interfaces, though.

Luke
  • 11,211
  • 2
  • 27
  • 38
  • 1
    Thanks, that was the right direction, but after a lot of readings on various website, I thinks it's not a wise decision.In my case I wanted to use these porperties to flag some file information (ntfs dependent ...), for more info you can aslo read http://users.telenet.be/ws36637/properties.html, http://www.forensicfocus.com/dissecting-ntfs-hidden-streams ... – Guillaume Mar 19 '12 at 18:10