I want a location to keep images. My first thought ended up being to make use of the database, but many seems to recommend using the filesystem. This appears to suit my situation, but how do you implement it?

The filenames have to be unique, how to achieve that. Must I make use of a guid?

How you can retrieve the files, must i go straight to the database while using filename, create a aspx page and passing either filename or primary key like a querystring after which browse the file.

How about client side caching, is the fact that enabled when utilizing a webpage like image.aspx?id=123 ?

How do you remove the files, once the connected record is erased?

I suppose you will find a number of other stuff that I still haven't considered.

Links, samples and recommendations are extremely welcome!

Uploading Files in ASP.NET 2.0

You appear up in mid-air concerning how to do that, so I'll provide you with a couple of suggestions to enable you to get going.

If you wish to make use of a file system make certain you realize the limit of the number of files are allowed per directory, so that you can setup a method that produces subdirectories. http://ask-leo.com/is_there_a_limit_to_what_a_single_folder_or_directory_can_hold.html

I'd create a table something similar to this :

UploadID          int identity/auto generate PK, used as FK in other tables
InternalFileName  string
DisplayFileName   string
Comment           string
MimeType          string
FileSizeBytes     int
FileHash          string MD5 Hash of a File
UploadUserID      int  FK to UserID
UploadDate        date

You'd range from the UploadID within the table that "is the owner of" this upload, such as the Order connected by using it, etc. You could include the InternalDirectory column, however i would rather calculate this with different constant Root value + some key specific value. For instance, the entire file title and directory could be:


You can result in the InternalFileName function as the UploadID and also the file extension in the original file. This way it might be unique, but You will need to place the row as part one from the process, increase it after once you be aware of file title and identity/auto generate row value. You can result in the InternalFileName something similar to YYYMMDDhhmissmmm and also the file extension in the original file, which might be unique enough depending on how you utilize subdirectories.

I love to store a MD5 Hash of a File making discovering replicates easy.

MimeType and FileSizeBytes are available in the file system, but when you store them within the database, it can make some maintenance simpler since query for big files or files of some types.