Saving files for asp.net web application
I'm creating a web application where the users can upload and download files. In the past, I've usually done so by saving the files as binary in a sql database. I did this because, this way, I know which files belong to which users (based on an ID). How would I do this if I plan on saving the files on the HDD? I figure I would create a unique folder per user (and I would save their files there), but I'm wondering what the standard or better way of approaching this.
Re: Saving files for asp.net web application
The simplest approach is to create a user table and another table for file location per user.
I would never save a file on the database, it takes ages to download vs a folder files and is not a good way to go, unless on special cases (that in your case, this does not apply).
So when a user first register (or you register him trough a console), write his/her's id on the user table and create a folder with , possibly, the username as the folder name. Every file uploaded by the user would have the path written to the file location table.
Just a very simple approach without security considerations and multiple folder path selections to get you started.
Re: Saving files for asp.net web application
Thanks. And what should happen if the user ends up uploading a file of the same name? Should my web application just rename it when it saves it in the unique user's folder?
Re: Saving files for asp.net web application
That is up to you i guess but you should probably warn that the file exist and either keep o copy and overwrite or just overwrite .