When userA uploads a file, his files will be uploaded to folderA, when userB, to folderB, and so on. Roles/Profiles in ASP.NET. Folders will be pre-existing. Anyone?
You'll probably want to hand-code that. There's nothing intrinsic to ASP.NET for managing user files. However, the code to do so should be relatively easy. Assuming the username is unique and never changes, you can combine the username with a path (use Path.Combine) and upload to that location. I would also lock down that location so that nobody else can access it.
The way that I've done it in the past is to use a base upload folder (say uploads) and in that folder create a folder using the user's ID from the DB. So the structure would be ..\uploads\145 for user with a user ID of 145.
The first thing that my code does is to check to see if the folder exists and if not then calls a Directory.Create() (or whatever the syntax is) to create the folder before uploading.
Further info that you might find helpful: I also rename the file using a GUID which avoids name conflicts if they upload 2 files with the same name. The downside is that you will normally need to maintain a table with the original filename and the physical (GUID) filename.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With