c# - 如何在 Metro 中将 cookie 保存到文件中?

标签 c# .net microsoft-metro .net-4.5

基本上,我需要知道如何在 .net 4.5 中编写这段代码。我在 MSDN 中找不到它。

private void Savecookie(string filename, CookieContainer rcookie)
{
    Stream stream = File.Open(filename, FileMode.Create);
    BinaryFormatter bFormatter = new BinaryFormatter();
    bFormatter.Serialize(stream, rcookie);
    stream.Close();
}

文件已被存储文件夹替换,我找不到 binaryformatter 的替代品。我不知道如何序列化文件的数据。

最佳答案

您可以使用 MemoryStream 获取字节数组形式的数据,然后可以将其保存到 StorageFile。

private byte[] SerializeCookies(CookieContainer rcookie) 
{ 
    MemoryStream stream = new MemoryStream();
    BinaryFormatter bFormatter = new BinaryFormatter(); 
    bFormatter.Serialize(stream, rcookie); 
    stream.Close(); 
    return stream.ToArray();
} 

关于c# - 如何在 Metro 中将 cookie 保存到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11488563/

相关文章:

c# - 模式对话框未关闭

c# - IIS 与 Windows 服务?

c# - 在 Windows 服务中获取计算机名称?

java - Droptiles by Omar AL Zabir 支持哪些 HTML5 功能?

xaml - WinRT 中的全局调度程序?

c# - Visual Studio 2017 工作室显示错误 'This application is in break mode' 并引发未处理的异常

C# 更改设置文件名

.net - 单个Linq-to-Entities查询中的多个SQL聚合函数

c++ - 现在微软基础类(MFC)值不值得学?

c# - 从本地驱动器(资源)加载文件作为存储文件