问题
My C# app syncs files from a remote document management system to a filesystem.
The document management system has metadata (date of last audit, secrecy, author...) which is associated with each file but not stored WITHIN each file.
The files can be anything (bmp, xwd, pdf, unknown binary)
I want to make these metadata visible on the local Windows filesystem.
But I can't store metadata WITHIN each file. For instance, changing the secrecy of a file must NOT modify the checksum of the file.
What is the best way to store this metadata?
I have heard about NTFS extended file attributes, is it something that applies to my scenario? This question about setting extended file properties has all answers talking about modifying the files themselves, which I must avoid.
If there is no standard solution, then I will store the metadata in a local SQLite database. But I would really prefer to use a standard solution so that other apps (explorer, gallery apps, etc) can display/modify the properties they understand (like "author")
回答1:
Alternate data streams is one of NTFS' less-known features. Quote from the page:
C:\test>echo "ADS" > test.txt:hidden.txt
C:\test>dir
Volume in drive C has no label.
Volume Serial Number is B889-75DB
Directory of C:>test
10/22/2003 11:22 AM
. 10/22/2003 11:22 AM
.. 10/22/2003 11:22 AM 0 test.txt
C:\test> notepad test.txt:hidden.txt
This will open the file in notepad and allow you to edit it and save it.
It is similar to the Macintosh resource fork, i.e. it allows associating arbitrary data with files, without it being part of the file itself. Explorer doesn't understand it by default, but you can write a column handler for it.
EDIT
Some metadata (such as Author and Title) can be saved using OLE document properties. I don't know if it modifies the file itself or not, though:
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);
}
来源:https://stackoverflow.com/questions/13172129/store-metadata-outside-of-file-any-standard-approach-on-modern-windows