Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I wire users with their respective folders in ASP.NET?

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?

like image 921
MarlonRibunal Avatar asked Mar 01 '23 07:03

MarlonRibunal


2 Answers

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.

like image 57
Haacked Avatar answered Mar 15 '23 17:03

Haacked


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.

like image 31
Guy Avatar answered Mar 15 '23 17:03

Guy