Can anyone suggest, how to check if xls file empty or not?
I have tried FileInfo("fname").Length == 0
But it's not working.
Thanks
An "empty" Excel file will still have an Excel file header, which is why your test for a size of 0 is failing.
You can use Excel Interop to see what the UsedRange is:
for .xls
you can try this - it works for me.
FileUpload1.SaveAs(Server.MapPath("~/FileUpload/") + path.Value);
Workbook book = Workbook.Load(Server.MapPath(("~/FileUpload/") + FileUpload1.FileName));
Worksheet sheet = book.Worksheets[0];
sheetCount.Value = sheet.Cells.LastRowIndex.ToString();
foreach (Worksheet ws in book.Worksheets)
{
if (ws.Cells.Rows.Count != 0)
{
ddlSheets.Items.Add(ws.Name.ToString());
}
}
I think there is not simple solution similar to one you have stated.
You will have to actually programatically read the file by some Excel parser and check if there are some data.