コード例 #1
0
    private bool UploadExcel()
    {
        try
        {
            string FILENAME = string.Empty;
            string OpenPath = string.Empty;
            string SaveLoc = string.Empty;
            string FileExt = string.Empty;
            string hp = string.Empty;
            ExcelReading objExcelData = new ExcelReading();
            string sFileName = string.Empty;
            FILENAME = fupExcelFile.PostedFile.FileName;

            if (FILENAME.Contains("\\"))
            {
                string[] strFile = FILENAME.Split('\\');
                int max = strFile.Length - 1;
                FILENAME = strFile[max].ToString();
            }

            //It is date-username-filename.3digit unique for the day and user numeric ext .xls
            //20111103-admin-filenamemax15char.001.xls
            SaveLoc = Server.MapPath("LeadBulkFiles\\");

            if (System.IO.Directory.Exists(SaveLoc) == false)
            {
                System.IO.DirectoryInfo di = System.IO.Directory.CreateDirectory(SaveLoc);
            }
            SaveLoc = Server.MapPath("LeadBulkFiles\\" + FILENAME);

            fupExcelFile.PostedFile.SaveAs(SaveLoc);

            DataSet ds = objExcelData.GetSalesExcelToDatasetLeads(SaveLoc);
            Session["ExcelDataset"] = ds;
            if (ds.Tables[0].Rows.Count > 0)
            {
                SaveData(ds);
            }

        }

        catch (Exception ex)
        {
            Response.Redirect("Error.aspx");
        }
        return true;
    }