Abhilash J A

Abhilash J A

  • 537
  • 2.4k
  • 597.1k

How to use Server.MapPath to go two folder using for loop?

Feb 17 2017 12:13 AM
 
Hello everyone,
 
I am working on MVC 5, I want to upload and save images on application's local folder. 
 
This is view,
 
 
 
 
After the upload, now getting 2 images on Controller,
 
 
 
 
 
I want to save Logo Images on this path
 
  1. string path = Server.MapPath("~") + "UploadedImages/PremiUserRegistration/LogoImage/" + file.FileName; 
 
And, Tittile Images on this path
 
  1. string path = Server.MapPath("~") + "UploadedImages/PremiUserRegistration/TitlePicture/" + file.FileName; 
 
I have tried,
  1. foreach (HttpPostedFileBase item in fileUpload)  
  2.            {  
  3.                if (item.ContentLength > 0)  
  4.                {  
  5.                    HttpFileCollectionBase files = Request.Files;  
  6.                    DataTable dt = new DataTable { Columns = { new DataColumn("Path") } };  
  7.                    for (int i = 0; i < files.Count; i++)  
  8.                    {  
  9.                        HttpPostedFileBase file = files[i];  
  10.                        string path = Server.MapPath("~") + "UploadedImages/PremiUserRegistration/LogoImage/" + file.FileName;                         
  11.                        //string path = Server.MapPath("~") + "UploadedImages/PremiUserRegistration/TitlePicture/" + file.FileName;  
  12.   
  13.                        if (file.FileName != "")  
  14.                        {  
  15.                            dt.Rows.Add(file.FileName);  
  16.                            file.SaveAs(path);  
  17.                        }  
  18.                    }  
  19.                }  
  20.            } 
 How can I do this? Please help me...

Answers (5)