AGE81

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


Re: Visual C# General Setting file info/attributes (author, subject, ..)

rtdev

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.






Re: Visual C# General Setting file info/attributes (author, subject, ..)

rtdev

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.





Re: Visual C# General Setting file info/attributes (author, subject, ..)

Jeris

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





Re: Visual C# General Setting file info/attributes (author, subject, ..)

AGE81

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




Re: Visual C# General Setting file info/attributes (author, subject, ..)

rtdev

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.






Re: Visual C# General Setting file info/attributes (author, subject, ..)

AGE81

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




Re: Visual C# General Setting file info/attributes (author, subject, ..)

rtdev

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





Re: Visual C# General Setting file info/attributes (author, subject, ..)

SQL Protection

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





Re: Visual C# General Setting file info/attributes (author, subject, ..)

Notes

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...