Bkuniyil
asked on
Memory error
Hi Experts,
Below is the code. I have 3 tables, the second table contains 100,000 rows ,its afiling at RenderControl with the
execption : Exception of type System.OutOfMemoryExceptio n was thrown.
Please advise.
Below is the code. I have 3 tables, the second table contains 100,000 rows ,its afiling at RenderControl with the
execption : Exception of type System.OutOfMemoryExceptio
Please advise.
foreach (Table table in tables)
{
StringWriter sw = new StringWriter(output);
HtmlTextWriter htw = new HtmlTextWriter(sw);
table.RenderControl(htw);
}
What actually is the code trying to do?
ASKER
Will finally save to a file
you have to write directly to file. Associate your writer with a FileStream.
What he said!
try with this:
TextWriter sw = new StreamWriter("somefile.html");
HtmlTextWriter htw = new HtmlTextWriter(sw);
foreach (Table table in tables)
{
table.RenderControl(htw);
}
htw.Close();
ASKER
The above code still saves only part of the data to the file "somefile.html"
what do you mean with "part of the data" ?
try to use Flush:
TextWriter sw = new StreamWriter("somefile.htm l");
HtmlTextWriter htw = new HtmlTextWriter(sw);
foreach (Table table in tables)
{
table.RenderControl(htw);
htw.Flush();
}
htw.Close();
TextWriter sw = new StreamWriter("somefile.htm
HtmlTextWriter htw = new HtmlTextWriter(sw);
foreach (Table table in tables)
{
table.RenderControl(htw);
htw.Flush();
}
htw.Close();
ASKER
I need to write the loop through each of the tables and write it to the StringBuilder object. Is there any way of doing it without writing it to a file?
StringBuilder output = new StringBuilder();
foreach (Table table in tables)
{
StringWriter sw = new StringWriter(output);
HtmlTextWriter htw = new HtmlTextWriter(sw);
table.RenderControl(htw);
}
ASKER
Is there a maximum value that a StringBuilder Object can hold, i get an Out of Memory error.Appreciate all help.
capacity of a StringBuilder class is 4GB.
ASKER
The file i am trying to build through the Stringbuilder object is 2MB file, it should work alright?
Yes, it should, unless something bad in your loop
ASKER
The code in the loop is pasted above.Please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.