12

I know that each file has metadata like title, subject, keywords and comments:

enter image description here

But what if I need custom metadata like tags for example?

Is it possible to do it with C#?

Sur
  • 191
  • 2
  • 3
  • 14
Sasha
  • 20,424
  • 9
  • 40
  • 57
  • If your question is just related to JPEG or PNG, you can find more information (including source code) here: https://stackoverflow.com/questions/29037442/write-metadata-to-both-jpg-and-png – Matt Aug 02 '22 at 07:35
  • @DanielMöller : "I want to know if I can create custom XMP metadata" warrants a new Question, the bounty is unlikely to help. – H H Aug 02 '22 at 13:32

5 Answers5

7

I know that each file has metadata like title, subject, keywords and comments

That is not true. Most file types do not have a 'standard' form of metadata.

In particular, PDF files don't have properties that Windows Explorer recognizes.

Metadata (file attributes) is not a function of the filesystem.

  • Office files use a structured format that allows for such attributes.
  • Jpeg ues EXIF, a different format
H H
  • 263,252
  • 30
  • 330
  • 514
6

If using NTFS you can store whatever you like in an Alternate data stream

test
  • 2,589
  • 2
  • 24
  • 52
Jesper Palm
  • 7,170
  • 31
  • 36
3

As per Jesper's comment, you can use the DSOFile library to read and write to Custom properties that are stored in ADS.
Works well for me though note the fact that the properties are lost when file is transferred to a different file system, including email. see http://www.keysolutions.com/blogs/kenyee.nsf/d6plinks/KKYE-79KRU6 for a 64bit implementation, link to MS original and comments.

LostPhysx
  • 3,573
  • 8
  • 43
  • 73
RobG
  • 53
  • 6
2

This will depend on whether the file type you are working with supports this. For example this will not be possible with a text file.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • i need it for office files (doc, xls, ppt...) and PDFs – Sasha Jul 13 '10 at 08:13
  • @Darin, is there any way to attach custom metadata to ANY file? I don't mind if it will only be readable by my program, or if I can teach Windows Explorer about it – Shimmy Weitzhandler May 06 '15 at 08:11
  • Yes you can, use an alternate data stream. .. oh Jesper Palm below me mentions this. I should add that I feel like these might not get copied or might get left over when copying between file systems so I'd mark the file with something like File+.ext or something so you know to look. I should really code up something to allow people to do this easier... edit: looks like there is https://dmitrybrant.com/adsmanager and robg's answer is interesting too. Hrmm.. – Brent Rittenhouse Dec 08 '18 at 20:49
0

Has anyone thought of using the File ID for this? You can get it via the command

fsutil file queryfileid "C:/my/path/example.txt"

This could be used to store information about this file in a separate storage-file associated with the id.

Matt
  • 25,467
  • 18
  • 120
  • 187
Simon S.
  • 111
  • 3
  • That returns something like `File ID is 0x0000000000000000003200000007963e` - how does that solve the question about metadata? Could you give an example how you would leverage it? – Matt Oct 28 '22 at 06:36
  • That ID is unique to the file and does not change when the file is moved. So you could store the metadata you want to save in a separate storage-textfile and then mark it with this ID. Then, when you want to get the metadata for any file, you just look in that storagefile if there is a field marked with the ID of that file and if yes, read the associated data. – Simon S. Oct 28 '22 at 07:06
  • Is there a .NET function available instead of `fsutil file queryfileid` that we can use directly in C# rather than having to execute fsutil.exe ? – Matt Oct 28 '22 at 13:29