c# - Find and append to file without loading it in memory? -
im writing simple xml file logging looks :
<root> <objects> </objects> </root>
the file created first time
using (xmlwriter = new xmltextwriter(filepathandname, system.text.encoding.utf8)) { xmlwriter.formatting = formatting.indented; xmlwriter.writestartdocument(); xmlwriter.writestartelement("root"); xmlwriter.writestartelement("objects"); xmlwriter.writeendelement(); xmlwriter.writeendelement(); xmlwriter.writeenddocument(); xmlwriter.close(); }
now need place objects(serialized data contracts in string format) within objects tag without loading memory.
i have found lot of suggestions on how loads entire file memory , thats no when files large.
my thought :
- open file kind of reader
- search end of file
</objects>
tag - store index , close reader/file
- open file again time writer
- write serlized datacontract index(just before
- close file
i'm not sure how in c#?
the solution me in case xml inclusion technique, not perfect login simplier. can use appendtofile instead of manipulate or read memory.
Comments
Post a Comment