Hi!
I'm having "a small" problem. I need to load the data from a Excel file in a Client computer, and read its contents in the server side...
When i debug, all is fine... but when i publish the website in the server and try to read a file, there are no worksheets (and the FileUpload.PostedFile.FileName only as the File name! In my computer, it as the FullPath and File name!)
Can anyone help me please?
I'm using this code:
{
...
var existingFile = new FileInfo(fuTextFile.PostedFile.FileName);
using (var package = new ExcelPackage(existingFile))
{
ExcelWorkbook workBook = package.Workbook;
if (workBook != null)
{
if (workBook.Worksheets.Count > 0)
{
ExcelWorksheet currentWorksheet = workBook.Worksheets.First();
DataTable dt = new DataTable("Equipamentos");
for (int i = 1; i < 27; i++)
{
Create_Columns(dt, currentWorksheet.Cells[1, i].Value.ToString());
}
for (int rowNumber = 2; rowNumber <= currentWorksheet.Dimension.End.Row; rowNumber++)
{
DataRow dr = dt.NewRow();
for (int i = 1; i < 27; i++)
{
if (currentWorksheet.Cells[rowNumber, i].Value != null)
{
dr[currentWorksheet.Cells[1, i].Value.ToString()] = currentWorksheet.Cells[rowNumber, i].Value.ToString().Substring(0,10);
}
else
dr[currentWorksheet.Cells[1, i].Value.ToString()] = "";
}
dt.Rows.Add(dr);
}
...
}
}
}
}
I'm having "a small" problem. I need to load the data from a Excel file in a Client computer, and read its contents in the server side...
When i debug, all is fine... but when i publish the website in the server and try to read a file, there are no worksheets (and the FileUpload.PostedFile.FileName only as the File name! In my computer, it as the FullPath and File name!)
Can anyone help me please?
I'm using this code:
{
...
var existingFile = new FileInfo(fuTextFile.PostedFile.FileName);
using (var package = new ExcelPackage(existingFile))
{
ExcelWorkbook workBook = package.Workbook;
if (workBook != null)
{
if (workBook.Worksheets.Count > 0)
{
ExcelWorksheet currentWorksheet = workBook.Worksheets.First();
DataTable dt = new DataTable("Equipamentos");
for (int i = 1; i < 27; i++)
{
Create_Columns(dt, currentWorksheet.Cells[1, i].Value.ToString());
}
for (int rowNumber = 2; rowNumber <= currentWorksheet.Dimension.End.Row; rowNumber++)
{
DataRow dr = dt.NewRow();
for (int i = 1; i < 27; i++)
{
if (currentWorksheet.Cells[rowNumber, i].Value != null)
{
dr[currentWorksheet.Cells[1, i].Value.ToString()] = currentWorksheet.Cells[rowNumber, i].Value.ToString().Substring(0,10);
}
else
dr[currentWorksheet.Cells[1, i].Value.ToString()] = "";
}
dt.Rows.Add(dr);
}
...
}
}
}
}