title: C#: Writing a CookieContainer to Disk and Loading Back In For Use
body: <p>I have a <strong><code>CookieContainer</code></strong> extracted from a HttpWebRequest/HttpWebResponse session named <em>CookieJar</em>. I want my application to store cookies between runs, so cookies collected in the <code>CookieContainer</code> on one run of the program will be used the next run, too.</p>
  
  <p>I think the way to do this would be to somehow write the contents of a CookieContainer to disk. My question is:</p>
  
  <ul>
  <li>How can you <strong>write a CookieContainer to the disk</strong>? Are there built-in functions for this, or, if not, what are the approaches people have taken? Are there any classes available for simplifying this?</li>
  <li>Once you've written a CookieContainer to the disk, <strong>how do you load it back in for use</strong>?</li>
  </ul>
  
  <p><strong>UPDATE:</strong> The first answer has suggested <strong>serialization</strong> of the <code>CookieContainer</code>. However, I am not very familiar with how to serialize and deserialize such complex objects. Could you provide some <strong>sample code</strong>? The suggestion was to utilise <code>SOAPFormatter</code>.</p>