|
-
August 19th, 2010, 12:49 PM
#1
StringBuilder and StreamReader
Hello,
I have code:
StringBuilder data = new StringBuilder();
StreamReader st = new StreamReader(Utility.FileName(ObjectToLoad));
while (!st.EndOfStream)
{
data.Append(st.ReadLine());
}
st.BaseStream.Close();
st.Close();
st.Dispose();
returnObject = DeserializeObject(data.ToString(), ObjectToLoad);
private static Object DeserializeObject(String pXmlizedString, Type ObjectToLoad)
{
XmlSerializer xs = new XmlSerializer(ObjectToLoad);
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return xs.Deserialize(memoryStream);
}
private static Byte[] StringToUTF8ByteArray(String pXmlString)
{
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(pXmlString);
return byteArray;
}
I am getting error + [System.OutOfMemoryException] as the file size is more than 5000 KB.
Please suggest me what should I use so that it can store and convert into the Object that I want it.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|