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 :

  1. open file kind of reader
  2. search end of file </objects> tag
  3. store index , close reader/file
  4. open file again time writer
  5. write serlized datacontract index(just before
  6. 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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -