Save data from LIST to text file

12,940

You have 3 options:

  1. Use the ToString() method in order to export the MacroEvent to a formatted text. You probably need to override the default implementation. Make sure to put all the information you need, otherwise you won't be able to retrieve them later. Reading and parsing the file is then needed to load the data.

  2. Use the builtin .net XML serialization feature. Write/Read operation is straightforward.

    http://msdn.microsoft.com/en-us/library/ms950721.aspx

    http://support.microsoft.com/kb/815813

  3. If you are not planning on using the data on another application, why not use the BinarySerializer? By far, the best method, but the resulting file won't be in text format.

    http://www.codeproject.com/Articles/1789/Object-Serialization-using-C

Share:
12,940
user1410644
Author by

user1410644

Updated on June 04, 2022

Comments

  • user1410644
    user1410644 over 1 year

    I'm using this library http://www.codeproject.com/Articles/28064/Global-Mouse-and-Keyboard-Library to record a macro. I want to know how to save the "events" in a text file to load them later?

    So, here is the LIST:

    List<MacroEvent> events = new List<MacroEvent>();
    

    What I need to do to get the data into a text file?

  • user1410644
    user1410644 about 11 years
    I've already tried with something like this, but it doesn't work. I'm getting just "GlobalMacroRecorder.MacroEvent" in the text file. Thanks for the answer anyway :)
  • user1410644
    user1410644 about 11 years
    The BinarySerializer is perfect. Thanks!