none
Setting file info/attributes (author, subject, ..)

    Question

  • Hello forum,

    I've searched the forum in vain.

    How can i set the file info (author, subject) of a file (PDF) as i can in
    the properties dialog on the 'info' tab of the file properties?

    In my opinion these options are available for all files in an ntfs
    file system. So it must possible to change them with c#, or
    am i wrong?

    Thanks

    A.Gempp
    Monday, October 29, 2007 4:04 PM

Answers

  • You can get at some of the Summary information like the CreationTime and LastAccessTime from the System.IO.FileInfo object. But I don't know of a way to get at the author, subject, etc.. values using just the .Net classes.

    I found this article that explains how to get at these values using the "OLE File Property Reader" COM object.
    http://www.developerfusion.co.uk/show/5093/

    Hope this helps. 

    Monday, October 29, 2007 7:50 PM
  • After playing around with the "OLE File Property Reader" a bit. This is what I found out.

    - You need to download the "Microsoft Developer Support OLE File Property Reader 2.1 Sample" from
    http://www.microsoft.com/downloads/details.aspx?FamilyId=9BA6FAC6-520B-4A0A-878A-53EC8300C4C2&displaylang=en
    - Create a new C# VS.NET project (I used a windows application in this case).
    - Add a reference to C:\DsoFile\dsofile.dll to you project (this was the default location).
    - Add a button to the form.
    - Add the following code to the button:
     
    Code Block

    private void button1_Click(object sender, EventArgs e)
    {
      //This is the PDF file we want to update.
      string filename = @"c:\temp\MyFile.pdf";
      //Create the OleDocumentProperties object.
      DSOFile.OleDocumentProperties dso = new DSOFile.OleDocumentProperties();
      //Open the file for writing if we can. If not we will get an exception.
      dso.Open(filename, false,

        DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
      //Set the summary properties that you want.
      dso.SummaryProperties.Title = "This is the Title";
      dso.SummaryProperties.Subject = "This is the Subject";
      dso.SummaryProperties.Company = "RTDev";
      dso.SummaryProperties.Author = "Ron T.";
      //Save the Summary information.
      dso.Save();
      //Close the file.
      dso.Close(false);
    }



    This will update the Title, Subject, Company and Author of the MyFile.pdf file.
    Monday, October 29, 2007 9:10 PM
  • You can implement this through the "Microsoft Shell Controls and Automation" (shell32.dll). For detailed information, you can visit:

    http://www.codeproject.com/cs/files/detailedfileinfo.asp

    Tuesday, October 30, 2007 3:19 AM

All replies

  • You can get at some of the Summary information like the CreationTime and LastAccessTime from the System.IO.FileInfo object. But I don't know of a way to get at the author, subject, etc.. values using just the .Net classes.

    I found this article that explains how to get at these values using the "OLE File Property Reader" COM object.
    http://www.developerfusion.co.uk/show/5093/

    Hope this helps. 

    Monday, October 29, 2007 7:50 PM
  • After playing around with the "OLE File Property Reader" a bit. This is what I found out.

    - You need to download the "Microsoft Developer Support OLE File Property Reader 2.1 Sample" from
    http://www.microsoft.com/downloads/details.aspx?FamilyId=9BA6FAC6-520B-4A0A-878A-53EC8300C4C2&displaylang=en
    - Create a new C# VS.NET project (I used a windows application in this case).
    - Add a reference to C:\DsoFile\dsofile.dll to you project (this was the default location).
    - Add a button to the form.
    - Add the following code to the button:
     
    Code Block

    private void button1_Click(object sender, EventArgs e)
    {
      //This is the PDF file we want to update.
      string filename = @"c:\temp\MyFile.pdf";
      //Create the OleDocumentProperties object.
      DSOFile.OleDocumentProperties dso = new DSOFile.OleDocumentProperties();
      //Open the file for writing if we can. If not we will get an exception.
      dso.Open(filename, false,

        DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
      //Set the summary properties that you want.
      dso.SummaryProperties.Title = "This is the Title";
      dso.SummaryProperties.Subject = "This is the Subject";
      dso.SummaryProperties.Company = "RTDev";
      dso.SummaryProperties.Author = "Ron T.";
      //Save the Summary information.
      dso.Save();
      //Close the file.
      dso.Close(false);
    }



    This will update the Title, Subject, Company and Author of the MyFile.pdf file.
    Monday, October 29, 2007 9:10 PM
  • You can implement this through the "Microsoft Shell Controls and Automation" (shell32.dll). For detailed information, you can visit:

    http://www.codeproject.com/cs/files/detailedfileinfo.asp

    Tuesday, October 30, 2007 3:19 AM
  • Thanks everybody.

    Using the dsofile.dll makes it possible. But i would prefer a solution that doesn't
    need a additional DLL.

    Using shell32.dll only allows reading but not writing attributes as far as i see.

    A.Gempp
    Tuesday, October 30, 2007 12:46 PM
  • Yes, I know what you mean. It would me nice to not need any additional DLL's. Maybe the .Net framework will add support for this in the next version of the framework.

    Wednesday, October 31, 2007 1:56 AM
  • Hello again,

    i'm trying to use the dsofile.dll to set the file info and on my development PC
    everything works well. But on another machine i get an exception that the
    COM-object hasn't been registerd.

    Do i have to register the DLL? Isn't there another way?

    Alex
    Wednesday, October 31, 2007 12:39 PM
  • Yes, the dsofile.dll is a COM object and needs to be registered.
    At the command line navigate to the directory where the dsofile.dll and run the regsvr32 command.

    Example: regsvr32 dsofile.dll
    Wednesday, October 31, 2007 1:49 PM
  • DSO file works great for what I need to do. The problem that I am having now is how do I automatically register that dll on a machine that I have published my application to?

     

    Thursday, November 01, 2007 6:10 PM
  • I think if you use an installer, you can get it to register DLLs, etc. for you.

    For example, here is a freeware installer (I haven't tried it, just found it on a search...) that claims to do just that:

    http://www.jrsoftware.org/isinfo.php


    On the main topic... I've been trying to write a little file Detail/Property editor that will work for all files and all details... Particularly on Vista with all the (new?) file details available.

    It seems that DSO should work, but I haven't tried it yet for some of the non-standard details that you see when you're in a folder in Vista, and click View -> Choose Details (Like Light Source, Link target, Mailing address, Mileage, Nickname, etc, etc.)

    I checked out the example someone linked to above on The Code Project which also looks interesting, and uses Shell32.dll instead.

    I *also* see a page called "Property Handlers" on MSDN at:

    http://msdn2.microsoft.com/en-us/library/bb776861(VS.85).aspx

    Which talks about Vista's "Open Metadata" that sounds like you can add whatever property/value pairs you want to a file... somehow..  :-/

    Still trying to figure what's best/most flexible, etc...

    Sunday, January 06, 2008 1:17 AM
  • I tried this with an .mp3 file.  I got all the code to run, but the mp3 title did not change.  If not, what do I need to change MP3 information?
    Wednesday, August 26, 2009 4:33 PM
  • Same problem as cboshdave. Code works fine but the change is not refleced.
    Wednesday, February 23, 2011 6:31 PM
  • Same problem here. I can modify the properties of pdf file successfully. also the code runs for mp3 files without any error. but then when i look up properties of mp3 file i find no change.

    any suggesstions?

    Saturday, September 08, 2012 1:35 AM
  • I found the same problem... I did find though, that if I read the information I wrote out (using the same program), it does in fact show what was saved.

    I'm thinking the "SummaryProperties" is a different layer that has been obfuscated from other layers that show in Windows Explorer.

    Why does this have to be so complicated?  Good grief.

    Microsoft probably went on a rampage during developing Vista to try and minimize virus threats and therefore took away some very useful features from their file systems.

    Thanks...

    Thursday, August 07, 2014 2:04 PM