I'm trying to get the worksheet names, but the datatable has 0 rows. Where am I going wrong.
string fileName = fileUploadExcel.PostedFile.FileName;
string fileType = Path.GetExtension(fileName);
string filePath = "~/Temp/"+fileName;
FileUploadExcel.SaveAs(Server.MapPath(filePath));
string connString ="";
if(fileType==".xls")
connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};
Extended Properties = \"Excel 8.0;HDR=Yes;IMEX=2\";",filePath);
else if(fileType==".xlsx")
connString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};
Extended Properties = \"Excel 12.0 xml;HDR=Yes;IMEX=2\";",filePath);
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection(connString);
conn.Open;
dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid,null);
if(dt!=null)
{
int count = dt.Rows.Count; //The count is 0 here
foreach(DataRow row in dt.Rows)
{
string sheetName = row["TABLE_NAME"].ToString();
}
}