Is it possible to add custom metadata to file?
Asked Answered
D

5

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#?

Dichromatism answered 13/7, 2010 at 8:3 Comment(2)
If your question is just related to JPEG or PNG, you can find more information (including source code) here: #29037942Juback
@DanielMöller : "I want to know if I can create custom XMP metadata" warrants a new Question, the bounty is unlikely to help.Ezaria
E
8

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 uses EXIF, a different format.
Ezaria answered 13/7, 2010 at 8:21 Comment(0)
A
7

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

Arboreous answered 13/7, 2010 at 8:30 Comment(0)
H
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.

Hipster answered 4/12, 2017 at 22:45 Comment(0)
M
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.

Marconigraph answered 13/7, 2010 at 8:7 Comment(3)
i need it for office files (doc, xls, ppt...) and PDFsDichromatism
@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 itMastoidectomy
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 dmitrybrant.com/adsmanager and robg's answer is interesting too. Hrmm..Subcortex
B
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.

Bouchard answered 27/10, 2022 at 10:14 Comment(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?Juback
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.Bouchard
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 ?Juback

© 2022 - 2024 — McMap. All rights reserved.