将任意数据附加到 DirectoryInfo/FileInfo?

发布于 2024-09-16 04:31:37 字数 174 浏览 1 评论 0原文

我有一个类似于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写下不归期 2024-09-23 04:31:37

可以使用 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.

还给你自由 2024-09-23 04:31:37

正如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文