exception of type 'system.outofmemoryexception' was thrown
-
Im writing this code for display data in excel, try { string Path = "G:\\AjanceReport\\TotalReportExcelfile_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + ".xls"; FileInfo FI = new FileInfo(Path); StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter); DataGrid DataGrd = new DataGrid(); DataGrd.DataSource = dsGrid; DataGrd.DataBind(); DataGrd.RenderControl(htmlWrite); string directory = Path.Substring(0, Path.LastIndexOf("\\"));// GetDirectory(Path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } System.IO.StreamWriter vw = new System.IO.StreamWriter(Path, true); stringWriter.ToString().Normalize(); vw.Write(stringWriter.ToString()); vw.Flush(); vw.Close(); WriteAttachment(FI.Name, "application/vnd.ms-excel", stringWriter.ToString()); } catch (Exception ex) { //throw new Exception(ex.Message); } but i see this error : exception of type 'system.outofmemoryexception' was thrown any body know what can i do???
-
Im writing this code for display data in excel, try { string Path = "G:\\AjanceReport\\TotalReportExcelfile_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + ".xls"; FileInfo FI = new FileInfo(Path); StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter); DataGrid DataGrd = new DataGrid(); DataGrd.DataSource = dsGrid; DataGrd.DataBind(); DataGrd.RenderControl(htmlWrite); string directory = Path.Substring(0, Path.LastIndexOf("\\"));// GetDirectory(Path); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } System.IO.StreamWriter vw = new System.IO.StreamWriter(Path, true); stringWriter.ToString().Normalize(); vw.Write(stringWriter.ToString()); vw.Flush(); vw.Close(); WriteAttachment(FI.Name, "application/vnd.ms-excel", stringWriter.ToString()); } catch (Exception ex) { //throw new Exception(ex.Message); } but i see this error : exception of type 'system.outofmemoryexception' was thrown any body know what can i do???
Hey, How many records do you have in your excel file? Are they too much, I mean System.OutOfMemoryException hits when there is not much memory left for the application? have a look at your excel and see whether you can optimize it.. -Anurag