HI
In my ASP.net Application i did the excel Export from grid
view by using EPPLUS DLL. before save that excel i want to delete the
file excel if already exists in the folder.but first time the excel was
Exported on the second time excel generation that excel file was not
able to delete and shows the error as
"System.IO.IOException: The process cannot access the file 'F:\Test\\report.xlsx' because it is being used by another process".
and also i was not able to delete the excel as manually that time error was thrown as
"The action can't be completed because the file is open in webdev.webserver.exe".i m using vs2005 and sql 2005 with IIS 6.0
kindly do the needful to fix this error.
Loading
KarthiPosted Apr 25, 2013, 3:01 AM
Thanks for ur reply i m using EPPLUS Dll and i already dispose the objects of the excel package but still i got the same error .here i attach my coding for ur reference
public static void exportToEPPExcelFile(DataTable data)
{
try
{
string path = ConfigurationManager.AppSettings["attachments"].ToString();
ExcelPackage ep = new ExcelPackage();
ExcelWorksheet ews = ep.Workbook.Worksheets.Add("PTP");
DataTable dt = data;
int colcnt = dt.Columns.Count;
int rowcnt = dt.Rows.Count;
string rowsCellRange = "A2:" + Convert.ToChar('A' + dt.Columns.Count - 1) + dt.Rows.Count * dt.Columns.Count;
ews.Cells["A1"].LoadFromDataTable(dt, true, OfficeOpenXml.Table.TableStyles.None);
ews.Cells[1, 1, 1, colcnt].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
ews.Cells[1, 1, 1, colcnt].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(0, 100, 0));
ews.Cells[1, 1, 1, colcnt].Style.Font.Color.SetColor(Color.White);
ews.Cells[1, 1, 1, colcnt].Style.Font.Bold = true;
ews.Cells[1, 1, 1, colcnt].Style.WrapText = true;
// ews.Cells[1, 1, 1, colcnt].AutoFilter = false;
ews.Cells[1, 1, 1, colcnt].AutoFitColumns(8);
//ews.Cells[1, 1, 1, colcnt].AutoFitColumns();
ews.Cells[1, 1, 1, colcnt].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
//FileInfo fi = new FileInfo( );
FileInfo fi = new FileInfo(path + @"\report.xlsx");
if (fi.Exists)
{
fi.Delete();
}
ep.SaveAs(fi);
ep.Dispose();
}
catch (Exception ex)
{
string hh = ex.ToString();
}
}
waiting for ur reply
Ravi ShekharPosted Apr 25, 2013, 1:06 AM
When you create first time xlsx file after that dispose your streamreader and streamwriter object.
if you dont dispose them current file is in open state. thats your application restrict you to delete your file first.
Please mark it as answer . If u satisfied with the suggestion
Regards,
Ravi
Anand KumarPosted Apr 25, 2013, 1:06 AM