Wednesday, August 8

How to Update previous Image URL During Update Mode?

Here i am showing you how to bind previous image url in a hidden field and Update that same one as well as different image url.


#region Update By NomineeID
        public void UpdateNomineeByID()
        {

            UHRMS_Nominee objNominee = new UHRMS_Nominee();
            objNominee.Employee_ID = int.Parse(Request.QueryString["EmployeeID"]);
            objNominee.Emp_Nominee_ID = int.Parse(hdnNomineeID.Value);
            objNominee.Relationship = TxtRelationship.Text;
            objNominee.Nominee_Name = TxtName.Text;
            //**************************************************************************//
            string Dob = TxtDob.Text;
            DateTimeFormatInfo dateTodateInfo = new DateTimeFormatInfo();
            dateTodateInfo.ShortDatePattern = "dd/MM/yyyy";
            DateTime validDObDate = Convert.ToDateTime(Dob, dateTodateInfo);
            //**************************************************************************//
            objNominee.Date_of_Birth = validDObDate;
            TextBox txtAddress = (TextBox)NomineeAddress.FindControl("txtAddress");
            objNominee.Address = txtAddress.Text;
            DropDownList ddlCity = (DropDownList)NomineeAddress.FindControl("ddlCity");
            objNominee.City_ID = int.Parse(ddlCity.SelectedItem.Value);
            TextBox txtZip = (TextBox)NomineeAddress.FindControl("txtZipCode");
            objNominee.Zip_code = txtZip.Text;
            TextBox txtPhone = (TextBox)NomineeAddress.FindControl("txtPhoneNo");
            objNominee.Phone_No = txtPhone.Text;
            TextBox txtMob = (TextBox)NomineeAddress.FindControl("txtFaxNo");
            objNominee.Mobile_No = txtMob.Text;
           
            objNominee.Email_ID = TxtEmailID.Text;
            objNominee.Modified_On = DateTime.Now;
            objNominee.ModifiedBy = 1;
            objNominee.Is_Active = true;
            objNominee.Is_Deleted = false;
            //**************************************************************************//

            if (FileUpload1.HasFile == false)
            {
             //Bind your image url in a hidden field hdnPhotoURL.Value="Image Url From Your Database";

                string[] photo = hdnPhotoURL.Value.Split(new char[] { '.' });
                int i = photo.Length;
                string extension = photo[i - 1];
 //if you do not want to change the name of that photo url you just take another hiddenfield and store the previous Employee Name and pass the value like TxtName.Text="Your previous name from database" ;
                string NewPhoto = Request.QueryString["Employee_ID"] + TxtName.Text + "." + extension;
                objNominee.Photo = NewPhoto;
              
            }
            else
            {
                //********** To rename the uploaded photo ************//
                string[] photo = FileUpload1.FileName.Split(new char[] { '.' });
                int i = photo.Length;
                string extension = photo[i - 1];
                string NewPhoto = Request.QueryString["Employee_ID"] + TxtName.Text + "." + extension;
                objNominee.Photo = NewPhoto;
                string newFile = "";
                for (int j = 0; j < i - 2; i++)
                {
                    newFile += photo[j];
                }

                //**********************************************************//

                FileUpload1.SaveAs(Server.MapPath("~/images/ERP/HRMS/Nominee/" + NewPhoto));

            }
            ERPManagement.GetInstance.UpdateNomineeByID(objNominee);
        }

        #endregion



Thanks 

    Shibashish Mohanty


No comments:

Post a Comment

Please don't spam, spam comments is not allowed here.

ShibashishMnty
shibashish mohanty