将任意数据附加到 DirectoryInfo/FileInfo?
我有一个类似于 SVN 的网站,但没有版本控制。用户可以上传和下载到项目,其中每个项目在服务器上都有一个目录(带有子目录和文件)。我想做的是将更多信息附加到文件中,例如谁上传的、下载了多少次等等。有没有办法对 FileInfo 执行此操作,或者我应该将其存储在表中,将其与绝对路径或其他路径相关联?这种方式听起来很狡猾并且容易出错:\
I have a site which is akin to SVN, but without the version control.. Users can upload and download to Projects, where each Project has a directory (with subdirs and files) on the server. What i'd like to do is attach further information to files, like who uploaded it, how many times its been downloaded, and so on. Is there a way to do this for FileInfo, or should I store this in a table where it associates itself with an absolute path or something? That way sounds dodgy and error prone :\
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以使用 NTFS(默认的 Windows 文件系统,我假设您正在使用它)将数据附加到任意文件。您可以使用备用数据流。 Microsoft 将其用于扩展元数据,例如 Office 文档中的作者和摘要信息。
但实际上,在我看来,数据库方法是合理的、广泛使用的,而且不易出错。修改原始文件并不是一个好主意,除非您实际上要更改其内容。
It is possible to append data to arbitrary files with NTFS (the default Windows filesystem, which I'm assuming you're using). You'd use alternate data streams. Microsoft uses this for extended metadata like author and summary information in Office documents.
Really, though, the database approach is reasonable, widely used, and much less error-prone, in my opinion. It's not really a good idea to be modifying the original file unless you're actually changing its content.
正如 Michael Petrotta 指出的那样,替代数据流是一个好主意。 这里有一个 C# 教程代码。 但实际上,数据库才是正确的选择。 SQL Compact 和 SQLite 影响相当低且易于使用。
As Michael Petrotta points out, alternate data streams are a nifty idea. Here's a C# tutorial with code. Really though, a database is the way to go. SQL Compact and SQLite are fairly low-impact and straightforward to use.