Monday 23 July 2018

hr management system part 6 asp net How to Upload and Change Profile Pic...



   public string file_upload(FileUpload fileupload)

        {

            string msg = "-1";



            if (fileupload.HasFile)

            {



                string fileextenion = Path.GetExtension(fileupload.FileName);



                if (fileextenion.ToLower() != ".png" && fileextenion.ToLower() != ".jpg")

                {

                    Response.Write("<script>alert('Only images are allowed to upload , please select jpg or png image.... '); </script> ");

                }

                else

                {

                    int filesize = fileupload.PostedFile.ContentLength;



                    if (filesize > 2097152) //cannot upload > 2 mb image......

                    {

                        Response.Write("<script>alert('Only images are allowed to upload that are size of less than 2 MB  '); </script> ");

                    }

                    else

                    {

                        Random r = new Random();

                        int r1 = r.Next();

                        int r2 = r.Next();

                        msg = "~/Content/Uploads/" + r1 + r2 + fileupload.FileName;

                        fileupload.SaveAs(Server.MapPath(msg));

                    }







                }









            }

            else

            {

                Response.Write("<script>alert('please select a file '); </script> ");



            }



            return msg;





        }


Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...