0

In C#, I would like to read file details from a specific file.
I've found an interesting thread: Read/Write 'Extended' file properties (C#)

it uses a call to the GetDetailsOf() method on the folder shell object included in shell32.dll.
It works fine but I have an issue: According to the Operating System language, the header string is never the same...('Name' for the filename property on an english Windows, 'Nom' on a french Windows).
So, it's not easy to retrieve specific values with the name of the property as it changes according to the language...
Is there a way to handle this easily?

Community
  • 1
  • 1
Steph Ragazzi
  • 381
  • 1
  • 4
  • 15

2 Answers2

0

Some properties are available through the FileInfo object. For example, if you want the creation time of the file you can do:

Fileinfo myFileInfo = new Fileinfo(@"C:\path\to\file");
DateTime ftime = myFileInfo.CreationTime;  
Stochastically
  • 7,616
  • 5
  • 30
  • 58
0

Is the FileInfo class not enough for your needs ?

FileInfo info = new FileInfo("fileName");
var name = info.Name;
var creationTime = info.CreationTime;
// etc ...

If not, tell more about which properties you'd like to read from your file.


Update to my answer :

I don't know about a library that would allow to read any type of document properties'

But here are a few ways for the formats you said,

PDF :

Extracting Additional Metadata from a PDF using iTextSharp

Read/Modify PDF Metadata using iTextSharp

So, iText ® is a library that allows you to create and manipulate PDF documents (from their website)

Office : (first link from MS stipulates that it applies to Word as well as Excel documents)

How to: Read from and Write to Document Properties

Listing properties of a word document in C#

Community
  • 1
  • 1
aybe
  • 15,516
  • 9
  • 57
  • 105