My C# app http://cmissync.github.com将文件从远程文档管理系统同步到文件系统。
文档管理系统具有与每个文件关联但不存储在每个文件内的元数据(上次审核日期、保密性、作者...)。
文件可以是任何内容(bmp、xwd、pdf、未知二进制文件)
我想让这些元数据在本地 Windows 文件系统上可见。
但我无法在每个文件中存储元数据。例如,更改文件的保密性不得修改文件的校验和。
存储此元数据的最佳方式是什么?
我听说过 NTFS扩展文件属性 http://en.wikipedia.org/wiki/Extended_file_attributes,它适用于我的场景吗?这个关于设置扩展文件属性的问题 https://stackoverflow.com/questions/5337683/how-to-set-extended-file-properties所有答案都在谈论修改文件本身,我必须避免这样做。
如果没有标准解决方案,那么我会将元数据存储在本地 SQLite 数据库中。但我真的更喜欢使用标准解决方案,以便其他应用程序(资源管理器、图库应用程序等)可以显示/修改它们理解的属性(例如“作者”)
备用数据流 http://www.bleepingcomputer.com/tutorials/windows-alternate-data-streams/是 NTFS 鲜为人知的功能之一。引用页面:
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.
它类似于 Macintosh 资源分支,即它允许将任意数据与文件关联,而无需它成为文件本身的一部分。默认情况下资源管理器不理解它,但你可以写一个列处理程序 http://www.codeproject.com/Articles/3747/Explorer-column-handler-shell-extension-in-C for it.
EDIT
一些元数据(例如作者和标题)可以使用保存OLE 文档属性 http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/bb887b05-2018-4978-b115-c8c98e3542ce/。但我不知道它是否修改了文件本身:
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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)