Tuesday, November 15, 2011

Upload files in C#


 protected void btnUpload_Click(object sender, EventArgs e)
    {

        if (FileUpload1.HasFile == true)
        {

            filePath = Server.MapPath("~/FileUpload/" + FileUpload1.FileName);

            string strExension = Path.GetExtension(filePath);
            if (strExension == ".xls")
            {
                FileUpload1.SaveAs(filePath);



                readExcel(filePath, "Source Data");


            }
            else
            {
                lblError.ForeColor = System.Drawing.Color.Red;
                lblError.Text = "Please select a file with .XLS file extension (Excel File).";
            }

No comments:

Post a Comment