Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Out of memory on loStringBuilder.ToString()
Message
From
07/06/2011 11:29:40
 
 
To
07/06/2011 09:19:31
General information
Forum:
ASP.NET
Category:
Troubleshooting
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01513090
Message ID:
01513349
Views:
38
Oh ... I thought you meant you found a way to use StringBuilder directly. Actually, I *did* find a way to do it this morning, but don't know if you'd still have the memory problem.

Instead of using the .ToString(), pass the StringBuilder itself:
'loStreamWriter.Write(toStringBuilder.ToString()) 'do not use this one

' use this instead
loStreamWriter.Write(toStringBuilder)
Did you try this variation and still run into memory problems?

~~Bonnie



>>Can you post the code that solved your problem? I was going to suggest something along those lines, but didn't get far because, with the encoding you were doing with the StreamWriter, I didn't find an applicable overload with the FileStream ... and, unfortunately, I didn't have the time to investigate it further. Others might benefit from your solution.
>
>
>            Dim loFileStream As FileStream = Nothing
>            Dim loStreamWriter As StreamWriter = Nothing
>
>            Try
>                loFileStream = New FileStream(cFile, FileMode.Create)
>                loStreamWriter = New StreamWriter(loFileStream, System.Text.Encoding.Unicode)
>
>            Catch loError As Exception
>                cMessage = oApp.StrTran(cCannotCreateFile, "##File##", cFile)
>
>                ' If we log the error
>                If lLogError Then
>
>                    ' Get the proper definition as per the current scope
>                    If oProcess Is Nothing Then
>                        oApp.ErrorSetup(loError)
>                    Else
>                        oProcess.ErrorSetup(loError)
>                    End If
>
>                Else
>                    Return False
>                End If
>
>            End Try
>
>            ' Header
>            loStreamWriter.Write("<?xml version=""1.0""?>" + oApp.cCR)
>
>            ' Windows recognition
>            loStreamWriter.Write("<?mso-application progid=""Excel.Sheet""?>" + oApp.cCR)
>
>            ' Workbook
>            loStreamWriter.Write("<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet"" " + oApp.cCR)
>            loStreamWriter.Write("xmlns:o=""urn:schemas-microsoft-com:office:office"" " + oApp.cCR)
>
>            ...
>
>            loStreamWriter.Close()
>            loFileStream.Close()
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform