views:

35

answers:

2

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 :\

+1  A: 

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
Thanks for that. Is my idea to "key" the DB entries to the absolute path appropriate? Are there any examples of doing such a thing?
George R
@George: when I've done this, I've typically had something at least "FileID" (primary key), and "File Name". Other metadata would go into this or related tables. On an upload, I rename the file to the (unique) file ID, and on download, I rename it back. We'd also group the files in batches of 100 or 500, to make manual directory traversal easier.
Michael Petrotta
A: 

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.

Matthew Ferreira