locked
Read/Write to app.config in Compact Framework RRS feed

  • Question

  • Im using OpenNETCF. im able to read from XML using 
    ConfigurationSettings.AppSettings["fieldname"];
    But now i need to write/append the file. I found an example here but it would not work with compact framework and OpenNETCF.

    I actually found a solution here but it wouldn't work properly on Compact Framework. Everytime I write to the file, it trims off a character. Strange..

    How can I go about this?

    Sunday, January 17, 2010 4:23 PM

Answers

  • That's just a normal DOM which is used by many applications. I don't believe I've seen anything like that.

    You might try using Save() overload which takes stream and explicitly flushing that stream after writing is done.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by ZHE ZHAO Friday, January 22, 2010 4:01 AM
    Monday, January 18, 2010 2:31 AM

All replies

  • Second sample seems to be usable on NETCF. What do you mean by "it trims off a character"? Have you tried debugging it to see why it does that?
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Sunday, January 17, 2010 5:49 PM
  • Hi Ilya,


    tks for the reply.


    for example, i have the following in my app.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="Setting1" value="Very" />
        <add key="Setting2" value="Easy" />
      </appSettings>
    </configuration>
    If write / append the file, it will be:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="Setting1" value="Very" />
        <add key="Setting2" value="Easy" />
      </appSettings>
    </configuratio
    Notice that the </configuration> now becomes </configuratio


    As i write / append further, it will the trim further too. I tried debugging but still clueless. I will look into it again
    Monday, January 18, 2010 2:03 AM
  • That's just a normal DOM which is used by many applications. I don't believe I've seen anything like that.

    You might try using Save() overload which takes stream and explicitly flushing that stream after writing is done.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by ZHE ZHAO Friday, January 22, 2010 4:01 AM
    Monday, January 18, 2010 2:31 AM