Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web form which consists of many fields.. First of them being App icon,App Description,Date and so on.. and finally there is SAVE Button.

Save button click event will take entire details of the form to date base(which is present in client system)..

The issue..i need to save to App Icon in my project root folder.. should i do that-my tasks involved in this project are done.. Can Someone help me out with this issue..

This is the code i tried for Saving it to my root folder(~Images/Profiles/(This is where the app icon needs to be Saved)

C#
public ActionResult SubmitApp(FormCollection fc, HttpPostedFileBase file)
 {
      //if (fc.Count != 0)
      //{
      //App_Of_The_DayEntities4 aod = new App_Of_The_DayEntities4();
   try
      {
        Submit_App sa = new Submit_App();
        sa.Actual_Price = Decimal.Parse(fc["actualprice"]);
        sa.App_Description = fc["description"];

        sa.App_Title = fc["title"];
        sa.iTunes_Link = fc["link"];
        sa.UserID = (long)Session["userid"];
       sa.Date = DateTime.Parse(fc["date"]);

      if (file != null)
        {
     string pic = System.IO.Path.GetFileName(file.FileName);
     string path = System.IO.Path.Combine(Server.MapPath("~/images/profile"), pic);
     // file is uploaded
     file.SaveAs(path);
     // save the image path path to the database or you can send image directly to database
     // in-case if you want to store byte[] ie. for DB
     using (MemoryStream ms = new MemoryStream())
       {
          file.InputStream.CopyTo(ms);
          byte[] array = ms.GetBuffer();
       }

   }
      //FileInfo fi = new FileInfo(@"E:\Wallpapers\Homeland5");
                    //fi.CopyTo(@"C:\Users\Sidd\Desktop\App_of_the_day\App_of_the_day\images\profiles\Homeland5.jpg");
                    sa.App_Icon = "/images/profile/";// +pic;
                    entity.AddToSubmit_App(sa);
                    entity.SaveChanges();
                }
                catch { ViewBag.error = "You have missed some fields please enter all fields"; }
                //}
                return View();
            }


[edit]Code block fixed - OriginalGriff[/edit]
Posted
Updated 20-Sep-13 20:41pm
v3
Comments
[no name] 15-Nov-13 1:03am    
What error you are getting....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900