VS'12 Ineternet Application Template asp.net C# MVC4, EF Code First
Upload Post Method
if (ModelState.IsValid)
{
foreach (var file in attachments)
{
string strMappath = "~/UploadedImages/" +var1+ "/" + var2+ "/" + var3+ "/" + var4+ "/" + var5 + "/";
if (!Directory.Exists(strMappath))
{
DirectoryInfo di = Directory.CreateDirectory(strMappath);
}
// Some browsers send file names with full path. We only care about the file name.
//var fileName = Path.GetFileName(file.FileName);
var fileName = Path.GetFileNameWithoutExtension(file.FileName) + Path.GetExtension(file.FileName);
var destinationPath = Path.Combine(
Server.MapPath(strMappath), fileName);
file.SaveAs(destinationPath);
}
My Questions are
This is for both on the Dev machine though IIS and on my Server-also IIS
Use Server.MapPath(strMappath)
to create folders and check if exist.