locked
in choose file option select file base file path is saved other remaining options pass null? RRS feed

  • Question

  • User-1026236167 posted

    hello 

    in my code button BT_submit_Click i have few choose file option  like image, adhar,sign,pan,licencing but when i select all means choose file from all options then it can run if condition of all  when i nothing select option else part is run so my requirement is i want when select one choose file option then one run and in  all other options null is passed when two select then two file path is saved and other can pass null

    here is my code 

    cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;

    namespace Store
    {
    public partial class WebForm7 : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {

    }
    }

    protected void BT_submit_Click(object sender, EventArgs e)
    {
    if (image1.HasFiles)
    {
    string fileName = Path.GetFileName(image1.PostedFile.FileName);
    string filePath = "~/img/" + fileName;

    image1.PostedFile.SaveAs(Server.MapPath(filePath));

    if (sign.HasFiles)
    {
    string fileName1 = Path.GetFileName(sign.PostedFile.FileName);
    string filePath1 = "~/img/" + fileName1;

    sign.PostedFile.SaveAs(Server.MapPath(filePath1));

    if (adharimg.HasFiles)
    {
    string fileName2 = Path.GetFileName(adharimg.PostedFile.FileName);
    string filePath2 = "~/img/" + fileName2;

    adharimg.PostedFile.SaveAs(Server.MapPath(filePath2));

    if (panimg.HasFiles)
    {
    string fileName4 = Path.GetFileName(panimg.PostedFile.FileName);
    string filePath4 = "~/img/" + fileName4;

    panimg.PostedFile.SaveAs(Server.MapPath(filePath4));

    if (licenseimg.HasFiles)
    {
    string fileName5 = Path.GetFileName(licenseimg.PostedFile.FileName);
    string filePath5 = "~/img/" + fileName5;

    licenseimg.PostedFile.SaveAs(Server.MapPath(filePath5));

    if (voterimg.HasFiles)
    {
    string fileName3 = Path.GetFileName(voterimg.PostedFile.FileName);
    string filePath3 = "~/img/" + fileName3;

    voterimg.PostedFile.SaveAs(Server.MapPath(filePath3));

    int status = 0;
    using (storeEntities3 ctx = new storeEntities3())
    {
    ctx.tbl_employee.Add(new tbl_employee()
    {

    user_id = TB_user.Text,
    password = TB_password.Text,
    person_name = TB_person.Text,
    mobile_no_1 = TB_mob1.Text,
    mobile_no_2 = TB_mob2.Text,
    address_1 = TB_add1.Text,
    address_2 = TB_add2.Text,
    email_1 = TB_email.Text,
    image = filePath,
    aadharcard_no = filePath2,

    pancard_no = filePath4,
    licencecard_no = filePath5,
    votercard_no = filePath3,
    remarks_1 = TB_remarks1.Text,
    remarks_2 = TB_remarks2.Text,
    remarks_3 = TB_remarks3.Text,
    remarks_4 = TB_remarks4.Text,
    remarks_5 = TB_remarks5.Text,
    remarks_6 = TB_remarks6.Text,
    account_holder_name = TB_holder.Text,
    bank_account_number = TB_account.Text,
    ifsc_code = TB_ifsc.Text,
    branch = TB_branch.Text,
    bank = TB_bank.Text,

    //by_whom = Session["username"].ToString(),

    date_time = System.DateTime.Now.ToLocalTime(),
    });


    status = ctx.SaveChanges();
    Response.Redirect(Request.Url.AbsoluteUri);
    }

    }
    }
    }
    }
    }
    }

    else
    {
    int status = 0;
    using (storeEntities3 ctx = new storeEntities3())
    {
    ctx.tbl_employee.Add(new tbl_employee()
    {

    user_id = TB_user.Text,
    password = TB_password.Text,
    person_name = TB_person.Text,
    mobile_no_1 = TB_mob1.Text,
    mobile_no_2 = TB_mob2.Text,
    address_1 = TB_add1.Text,
    address_2 = TB_add2.Text,
    email_1 = TB_email.Text,
    aadharcard_no = TB_aadharno.Text,
    image = "null",

    pancard_no = TB_panno.Text,

    licencecard_no = TB_licenseno.Text,

    votercard_no = TB_voterno.Text,
    remarks_1 = TB_remarks1.Text,
    remarks_2 = TB_remarks2.Text,
    remarks_3 = TB_remarks3.Text,
    remarks_4 = TB_remarks4.Text,
    remarks_5 = TB_remarks5.Text,
    remarks_6 = TB_remarks6.Text,
    account_holder_name = TB_holder.Text,
    bank_account_number = TB_account.Text,
    ifsc_code = TB_ifsc.Text,
    branch = TB_branch.Text,
    bank = TB_bank.Text,

    //by_whom = Session["username"].ToString(),

    date_time = System.DateTime.Now.ToLocalTime(),
    });


    status = ctx.SaveChanges();
    Response.Redirect(Request.Url.AbsoluteUri);


    }
    }



    }
    }
    }

    aspx

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm7.aspx.cs" Inherits="Store.WebForm7" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="contentbody" runat="server">

    <form id="form1" runat="server">

    <div class="container-fluid">


    <h3 style="color:black; font-size:2.8em">Manage Employee</h3>
    <hr />


    <br /> <h3 style="color:black; ">Basic Info</h3>
    <hr />


    <div class="row">
    <div class="col-sm-3">
    <span style="color:black;"><b>

    User id *</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_user" runat="server" Width="240px" /></span><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="required" ControlToValidate="TB_user" ForeColor="Red" ></asp:RequiredFieldValidator>

    </div>
    <div class="col-sm-3">
    <span style="color:black;"><b>

    Password *</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_password" runat="server" Width="240px" /></span><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="required" ControlToValidate="TB_password" ForeColor="Red" ></asp:RequiredFieldValidator>

    </div>

    <div class="col-sm-3">

    <span style="color:black"><b>Person Name *</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_person" runat="server" Width="240px"/></span><br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="required" ControlToValidate="TB_person" ForeColor="Red" ></asp:RequiredFieldValidator>

    </div>
    <div class="col-sm-3">
    <span style="color:black; "><b>Email</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_email" runat="server" Width="240px" placeholder="jsrtech@gmail.com" /></span><br />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TB_email" ErrorMessage=" eg. you@gmail.com" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ForeColor="red" ></asp:RegularExpressionValidator>


    </div>




    </div>


    <div class="row">

    <div class="col-sm-3">

    <span style="color:black"><b>Salary</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_salary" runat="server" Width="240px"/></span><br />

    </div>

    <div class="col-sm-3">

    <span style="color:black"><b>Image</b></span><br />
    <span style="color:black"> <asp:fileupload ID ="image1" runat="server" Width="240px"/></span><br />

    </div>
    <div class="col-sm-3">

    <span style="color:black"><b>Signature</b></span><br />
    <span style="color:black"> <asp:fileupload ID ="sign" runat="server" Width="240px"/></span><br />

    </div>


    </div>



    <br /><h3 style="color:black; ">Contact Details</h3>
    <hr />

    <div class="row">

    <div class="col-sm-3">
    <span style="color:black"><b>

    Select Country</b></span><br />
    <span style="color:black"> <asp:dropdownlist ID ="dd1" runat="server" Width="240px" Height="30" DataTextField="country" /></span><br />


    </div>
    <div class="col-sm-3">
    <span style="color:black;"><b>


    Select State</b></span><br />
    <span style="color:black; "> <asp:dropdownlist ID ="dd2" runat="server" Width="240px" Height="30" DataTextField="state"/></span><br />



    </div>
    <div class="col-sm-3">
    <span style="color:black;"><b>


    Select City</b></span><br />
    <span style="color:black; "> <asp:dropdownlist ID ="dd3" runat="server" Width="240px" Height="30" DataTextField="city"/></span><br />


    </div>
    <div class="col-sm-3">
    <span style="color:black; "><b>Mobile No.1</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_mob1" runat="server" Width="240px" placeholder="8541236523" /></span><br />
    <asp:RegularExpressionValidator ID="r1" runat="server" ControlToValidate="TB_mob1" ErrorMessage="Invalid Number" ValidationExpression="^([6-9]{1})([0-9]{9})$" ForeColor="Red"></asp:RegularExpressionValidator>

    </div> </div>
    <div class="row">

    <div class="col-sm-3">
    <span style="color:black; "><b>Mobile No.2</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_mob2" runat="server" Width="240px" placeholder="8541236523" /></span><br />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid number" ControlToValidate="TB_mob2" ValidationExpression="^([6-9]{1})([0-9]{9})$" ForeColor="Red"></asp:RegularExpressionValidator>

    </div>

    <div class="col-sm-3">
    <span style="color:black; "><b>Pincode</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TextBox1" runat="server" Width="240px" /></span><br />

    </div>
    <div class="col-sm-6">
    <span style="color:black; "><b> Address 1</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_add1" runat="server" Width="515px"/></span><br />

    </div>

    </div>
    <div class="row">
    <div class="col-sm-6">
    <span style="color:black; "><b> Address 2</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_add2" runat="server" Width="515px"/></span><br />

    </div>


    </div>

    <div class="row">

    </div>


    <br /><br /> <h3 style="color:black; ">Documents Information</h3>
    <hr />

    <div class="row">
    <div class="col-sm-3">
    <span style="color:black"><b>
    <br />Aadhar Card Image

    </b></span><br />
    <span style="color:black; "> <asp:fileupload ID ="adharimg" runat="server" Width="240" /></span><br />

    </div>
    <div class="col-sm-3">
    <b>
    <br />
    Aadhar Card No. </b><br />
    <asp:TextBox ID ="TB_aadharno" runat="server" Width="240px" /><br />

    </div>

    <div class="col-sm-3">
    <span style="color:black"><b>
    <br />Pan Card Image

    </b></span><br />
    <span style="color:black; "> <asp:fileupload ID ="panimg" runat="server" Width="240" /></span><br />

    </div>
    <div class="col-sm-3">
    <b>
    <br />
    Pan Card No. </b><br />
    <asp:TextBox ID ="TB_panno" runat="server" Width="240px" /><br />

    </div>

    </div>


    <div class="row">
    <div class="col-sm-3">
    <span style="color:black"><b>
    <br /> Vehicle License Image

    </b></span><br />
    <span style="color:black; "> <asp:fileupload ID ="licenseimg" runat="server" Width="240" /></span><br />

    </div>
    <div class="col-sm-3">
    <b>
    <br />
    Vehicle License No. </b><br />
    <asp:TextBox ID ="TB_licenseno" runat="server" Width="240px" /><br />

    </div>

    <div class="col-sm-3">
    <span style="color:black"><b>
    <br />Voter Card Image

    </b></span><br />
    <span style="color:black; "> <asp:fileupload ID ="voterimg" runat="server" Width="240" /></span><br />

    </div>
    <div class="col-sm-3">
    <b>
    <br />
    Voter Card No. </b><br />
    <asp:TextBox ID ="TB_voterno" runat="server" Width="240px" /><br />

    </div>

    </div>




    <br /> <br /> <h3 style="color:black; ">Bank Details</h3>
    <hr />
    <div class="row">
    <div class="col-sm-3">

    <span style="color:black;"> <b> Account Holder Name</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_holder" runat="server" Width="240px" /></span><br />
    </div>
    <div class="col-sm-3">
    <span style="color:black; "><b>


    Account No.</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_account" runat="server" Width="240px"/></span><br />
    </div>
    <div class="col-sm-3">

    <span style="color:black; "><b>

    Ifsc Code</b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_ifsc" runat="server" Width="240px" /></span><br />
    </div>

    <div class="col-sm-3">

    <span style="color:black;"><b>

    Bank Name </b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_bank" runat="server" Width="240px" /></span><br />
    </div>

    </div>

    <div class="row">
    <div class="col-sm-3">

    <span style="color:black;"><b>
    <br />
    Bank Branch </b></span><br />
    <span style="color:black; "> <asp:TextBox ID ="TB_branch" runat="server" Width="240px" /></span><br />
    </div>

    </div>



    <br /><br /> <h3 style="color:black; ">Remarks</h3>
    <hr />
    <div class="row">

    <div class="col-sm-6">
    <span style="color:black"><b>

    Remarks 1</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_remarks1" runat="server" Width="500px"/></span><br />


    </div>
    <div class="col-sm-6">
    <span style="color:black"><b>

    Remarks 2</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_remarks2" runat="server" Width="500px"/></span><br />


    </div>

    </div>

    <div class="row">
    <div class="col-sm-6">
    <span style="color:black"><b>
    <br />
    Remarks 3</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_remarks3" runat="server" Width="500px"/></span><br />


    </div>
    <div class="col-sm-6">
    <span style="color:black"><b>
    <br />
    Remarks 4</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_remarks4" runat="server" Width="500px"/></span><br />


    </div></div>
    <div class="row">
    <div class="col-sm-6">
    <span style="color:black"><b>
    <br />
    Remarks 5</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_remarks5" runat="server" Width="500px"/></span><br />


    </div>
    <div class="col-sm-6">
    <span style="color:black"><b>
    <br />
    Remarks 6</b></span><br />
    <span style="color:black"> <asp:TextBox ID ="TB_remarks6" runat="server" Width="500px"/></span><br />


    </div></div>
    <br />
    <div class="row">
    <div class="col-sm-4">
    <asp:Button ID="BT_submit" runat="server" Text="Submit" style="border-radius:5px" Height="41px" Width="145px" BackColor="#000000" BorderColor="#000000" ForeColor="White" OnClick="BT_submit_Click" />
    </div>
    </div> <br />

    </div>
    </form>
    </asp:Content>

    Friday, August 14, 2020 5:32 AM

Answers

  • User1686398519 posted

    Hi prabhjot1313

    The previous example is based on the model created by the code you provided, and the above example is given based on the logic of the code you provided.

    According to your needs, you need to create new fields to store the path of the uploaded file. I have added some fields and modified the example. Please refer to it.

    1. "filepath" is used to determine whether the uploaded file exists, if it exists, it returns the uploaded file path, otherwise it returns null.
    2. image path is not stored

      • You need to check if the size of the file you upload is empty.
      • HasFiles:This method also returns false if an empty file (zero bytes) is uploaded.

    tbl_employee.cs

        public class tbl_employee
        {
            [Key]
            public string user_id { get; set; }
            public string password { get; set; }
            public string person_name { get; set; }
            public string mobile_no_1 { get; set; }
            public string mobile_no_2 { get; set; }
            public string address_1 { get; set; }
            public string address_2 { get; set; }
            public string email_1 { get; set; }
            public string image { get; set; }
            public string aadharcard_no { get; set; }
            public string pancard_no { get; set; }
            public string licencecard_no { get; set; }
            public string votercard_no { get; set; }
            public string signature_path { get; set; }
            public string aadharcard_path { get; set; }
            public string pancard_path { get; set; }
            public string licencecard_path { get; set; }
            public string votercard_path { get; set; }
            public string remarks_1 { get; set; }
            public string remarks_2 { get; set; }
            public string remarks_3 { get; set; }
            public string remarks_4 { get; set; }
            public string remarks_5 { get; set; }
            public string remarks_6 { get; set; }
            public string account_holder_name { get; set; }
            public string bank_account_number { get; set; }
            public string ifsc_code { get; set; }
            public string branch { get; set; }
            public string bank { get; set; }
            public DateTime date_time { get; set; }
        }

    xxxx.aspx.cs

    public string filepath(FileUpload file)
            {
                if (file.HasFiles)
                {
                    string savefilePath = Server.MapPath("~/img/");
                    if (!Directory.Exists(savefilePath))
                    {
                        Directory.CreateDirectory(savefilePath);
                    }
    //Generate unique names string fileName = file.ClientID+DateTime.Now.Ticks.ToString()+Path.GetExtension(file.PostedFile.FileName); string filePath = Path.Combine(savefilePath,fileName); file.PostedFile.SaveAs(filePath); return filePath; } else { return null; } } protected void BT_submit_Click(object sender, EventArgs e) { int status = 0; using (storeEntities3 ctx = new storeEntities3()) { ctx.tbl_employee.Add(new tbl_employee() { user_id = TB_user.Text, password = TB_password.Text, person_name = TB_person.Text, mobile_no_1 = TB_mob1.Text, mobile_no_2 = TB_mob2.Text, address_1 = TB_add1.Text, address_2 = TB_add2.Text, email_1 = TB_email.Text, image = filepath(image1), signature_path= filepath(sign), aadharcard_path = filepath(adharimg), pancard_path =filepath(panimg), licencecard_path = filepath(licenseimg), votercard_path = filepath(voterimg), aadharcard_no =TB_aadharno.Text, pancard_no =TB_panno.Text, licencecard_no =TB_licenseno.Text, votercard_no =TB_voterno.Text, remarks_1 = TB_remarks1.Text, remarks_2 = TB_remarks2.Text, remarks_3 = TB_remarks3.Text, remarks_4 = TB_remarks4.Text, remarks_5 = TB_remarks5.Text, remarks_6 = TB_remarks6.Text, account_holder_name = TB_holder.Text, bank_account_number = TB_account.Text, ifsc_code = TB_ifsc.Text, branch = TB_branch.Text, bank = TB_bank.Text, //by_whom = Session["username"].ToString(), date_time = System.DateTime.Now.ToLocalTime(), }); status = ctx.SaveChanges(); Response.Redirect(Request.Url.AbsoluteUri); } }

    Here is the result.

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2020 3:33 AM

All replies

  • User1686398519 posted

    Hi prabhjot1313,

    I want to confirm with you:

    1. For img1, if you choose to upload a file, set the path, if not, set it to empty.
    2. For others, such as adharimg, if you choose to upload files, the path will be stored; if not, the value of TB_aadharno will be stored.

    If you have this requirement, please refer to the revised code below.

    If not, can you clearly describe your problem? If possible, you can add punctuation so that I can better understand what you mean.

            public string filepath(FileUpload file)
            {
                if (file.HasFiles)
                {
                    string savefilePath = Server.MapPath("~/img/");
                    if (!Directory.Exists(savefilePath))
                    {
                        Directory.CreateDirectory(savefilePath);
                    }
                    string fileName = Path.GetFileName(file.PostedFile.FileName);
                    string filePath = Path.Combine(savefilePath,fileName);
                    sign.PostedFile.SaveAs(filePath);
                    return filePath;
                }
                else
                {
                    return null;
                }
            }
            protected void BT_submit_Click(object sender, EventArgs e)
            {
                    int status = 0;
                    using (storeEntities3 ctx = new storeEntities3())
                    {
                        ctx.tbl_employee.Add(new tbl_employee()
                        {
                            user_id = TB_user.Text,
                            password = TB_password.Text,
                            person_name = TB_person.Text,
                            mobile_no_1 = TB_mob1.Text,
                            mobile_no_2 = TB_mob2.Text,
                            address_1 = TB_add1.Text,
                            address_2 = TB_add2.Text,
                            email_1 = TB_email.Text,
    
                            image = filepath(image1),
                            aadharcard_no =filepath(adharimg)==null? TB_aadharno.Text : filepath(adharimg),
                            pancard_no =filepath(panimg)==null? TB_panno.Text : filepath(panimg),
                            licencecard_no = filepath(licenseimg)==null? TB_licenseno.Text : filepath(licenseimg),
                            votercard_no = filepath(voterimg)==null?TB_voterno.Text: filepath(voterimg),
    
                            remarks_1 = TB_remarks1.Text,
                            remarks_2 = TB_remarks2.Text,
                            remarks_3 = TB_remarks3.Text,
                            remarks_4 = TB_remarks4.Text,
                            remarks_5 = TB_remarks5.Text,
                            remarks_6 = TB_remarks6.Text,
                            account_holder_name = TB_holder.Text,
                            bank_account_number = TB_account.Text,
                            ifsc_code = TB_ifsc.Text,
                            branch = TB_branch.Text,
                            bank = TB_bank.Text,
                            //by_whom = Session["username"].ToString(),
                            date_time = System.DateTime.Now.ToLocalTime(),
                        });
                        status = ctx.SaveChanges();
                        Response.Redirect(Request.Url.AbsoluteUri);
                    }
            }

    Here is the result.

    Best Regards,

    YihuiSun

    Friday, August 14, 2020 9:28 AM
  • User-1026236167 posted

    sir my requirement is simple when adharimg pan any of these selected file then filepath is saved in the db otherwise not selected file null is saved in the databse 

    Friday, August 14, 2020 10:57 AM
  • User-1026236167 posted

    sir i apply this code in my webform but in signature column of databse image path is not stored and u apply this code in as adharcard_no pancard_no am stored this image path in their related like adharcard_image not adharcard_no

    Saturday, August 15, 2020 9:05 AM
  • User1686398519 posted

    Hi prabhjot1313

    The previous example is based on the model created by the code you provided, and the above example is given based on the logic of the code you provided.

    According to your needs, you need to create new fields to store the path of the uploaded file. I have added some fields and modified the example. Please refer to it.

    1. "filepath" is used to determine whether the uploaded file exists, if it exists, it returns the uploaded file path, otherwise it returns null.
    2. image path is not stored

      • You need to check if the size of the file you upload is empty.
      • HasFiles:This method also returns false if an empty file (zero bytes) is uploaded.

    tbl_employee.cs

        public class tbl_employee
        {
            [Key]
            public string user_id { get; set; }
            public string password { get; set; }
            public string person_name { get; set; }
            public string mobile_no_1 { get; set; }
            public string mobile_no_2 { get; set; }
            public string address_1 { get; set; }
            public string address_2 { get; set; }
            public string email_1 { get; set; }
            public string image { get; set; }
            public string aadharcard_no { get; set; }
            public string pancard_no { get; set; }
            public string licencecard_no { get; set; }
            public string votercard_no { get; set; }
            public string signature_path { get; set; }
            public string aadharcard_path { get; set; }
            public string pancard_path { get; set; }
            public string licencecard_path { get; set; }
            public string votercard_path { get; set; }
            public string remarks_1 { get; set; }
            public string remarks_2 { get; set; }
            public string remarks_3 { get; set; }
            public string remarks_4 { get; set; }
            public string remarks_5 { get; set; }
            public string remarks_6 { get; set; }
            public string account_holder_name { get; set; }
            public string bank_account_number { get; set; }
            public string ifsc_code { get; set; }
            public string branch { get; set; }
            public string bank { get; set; }
            public DateTime date_time { get; set; }
        }

    xxxx.aspx.cs

    public string filepath(FileUpload file)
            {
                if (file.HasFiles)
                {
                    string savefilePath = Server.MapPath("~/img/");
                    if (!Directory.Exists(savefilePath))
                    {
                        Directory.CreateDirectory(savefilePath);
                    }
    //Generate unique names string fileName = file.ClientID+DateTime.Now.Ticks.ToString()+Path.GetExtension(file.PostedFile.FileName); string filePath = Path.Combine(savefilePath,fileName); file.PostedFile.SaveAs(filePath); return filePath; } else { return null; } } protected void BT_submit_Click(object sender, EventArgs e) { int status = 0; using (storeEntities3 ctx = new storeEntities3()) { ctx.tbl_employee.Add(new tbl_employee() { user_id = TB_user.Text, password = TB_password.Text, person_name = TB_person.Text, mobile_no_1 = TB_mob1.Text, mobile_no_2 = TB_mob2.Text, address_1 = TB_add1.Text, address_2 = TB_add2.Text, email_1 = TB_email.Text, image = filepath(image1), signature_path= filepath(sign), aadharcard_path = filepath(adharimg), pancard_path =filepath(panimg), licencecard_path = filepath(licenseimg), votercard_path = filepath(voterimg), aadharcard_no =TB_aadharno.Text, pancard_no =TB_panno.Text, licencecard_no =TB_licenseno.Text, votercard_no =TB_voterno.Text, remarks_1 = TB_remarks1.Text, remarks_2 = TB_remarks2.Text, remarks_3 = TB_remarks3.Text, remarks_4 = TB_remarks4.Text, remarks_5 = TB_remarks5.Text, remarks_6 = TB_remarks6.Text, account_holder_name = TB_holder.Text, bank_account_number = TB_account.Text, ifsc_code = TB_ifsc.Text, branch = TB_branch.Text, bank = TB_bank.Text, //by_whom = Session["username"].ToString(), date_time = System.DateTime.Now.ToLocalTime(), }); status = ctx.SaveChanges(); Response.Redirect(Request.Url.AbsoluteUri); } }

    Here is the result.

    Best Regards,

    YihuiSun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2020 3:33 AM
  • User1686398519 posted

    Hi prabhjot1313,

    Have your problem been solved?If you still meet problems, you can post it here and people here will be happy to solve the problem.

    Best Regards,

    YihuiSun

    Tuesday, August 18, 2020 9:56 AM