Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

You can just check for the existance of the folder and create it for the user if it doesn't exists, but there are security implications for this. You might also want to try and store data in a database and tie it to a user.. this depends on what you are letting users upload I guess.

There are a few ways you can do this:

Using Forms Authentication

If you use forms authentication, you can set a convention wherein a user's username or id can serve as the basis for a path in your server where the user can upload a file. Note that your user will not have direct access to that folder: the user should be able to download the files from your server via your web application as well.

Using Windows Authentication

If you use windows (e.g., ActiveDirectory) authentication, you can provide user access to both the physical location of the folder and via a web application.

P.S. - Glad to see you here Marlon!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top