Hi,
In my current project users can upload multiple files. Where is the best place to store the files? A very crucial point is authentication.
Only the Administrator shoud be allowed to download the files but the ordinary user shoud be allowed to upload his files.
I managed the multiple upload by my own upload page:
Code:
if (Request.HttpMethod == "POST")
{
string firstName = Request.Form["firstName"];
string lastName = Request.Form["lastname"];
string userFolder = firstName + "_" + lastName;
foreach (string file in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength == 0)
{
continue;
}
string savedFileName = "";
if (String.IsNullOrEmpty(userFolder.Replace("_", "")))
{
savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "/Cms_Data/Contents/Kooboo_CMS/Media/Bewerbungen/", Path.GetFileName(hpf.FileName) + "_" + DateTime.Now.ToString("yyyy.MM.dd hh:mm:ss"));
}
else
{
string folderPath = AppDomain.CurrentDomain.BaseDirectory + "/Cms_Data/Contents/Kooboo_CMS/Media/Bewerbungen/" + userFolder;
System.IO.Directory.CreateDirectory(folderPath);
savedFileName = Path.Combine(folderPath + "/", userFolder + "_" + Path.GetFileName(hpf.FileName));
}
hpf.SaveAs(savedFileName);
}
}
One way I can think of is to have a upload folder and then copy the files to a secured folder.
I'm also very new to kooboo and razor mvc3, so code examples would be very appreciated.
What's the best practice for that requirement?
thx a lot!