Store metadata outside of file: Any standard approach on modern Windows?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 16:17:51

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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!