using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography.X509Certificates;
public static bool WriteCookiesToDisk(string file, CookieContainer cookieJar)
{
//file = file.Replace(":", ":");
if (file == "") return false ;
using (Stream stream = File.Create(file))
{
try
{
//Console.Out.Write("Writing cookies to disk... ");
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, cookieJar);
//Console.Out.WriteLine("Done.");
return true;
}
catch (Exception e)
{
// Console.Out.WriteLine("Problem writing cookies to disk: " + e.GetType());
}
}
return false;
}
public static CookieContainer ReadCookiesFromDisk(string file)
{
// file = file.Replace(":", ":");
try
{
using (Stream stream = File.Open(file, FileMode.Open))
{
// Console.Out.Write("Reading cookies from disk... ");
BinaryFormatter formatter = new BinaryFormatter();
// Console.Out.WriteLine("Done.");
return (CookieContainer)formatter.Deserialize(stream);
}
}
catch (Exception e)
{
// Console.Out.WriteLine("Problem reading cookies from disk: " + e.GetType());
//return new CookieContainer();
return new CookieContainer();
}
}