0

これまでシリアライズしたことがないので、これを行う方法を理解するのに苦労しています。文字列をバイト [] に変換して新しい文字列にシリアル化することはできますが、そのシリアル化された文字列をテキスト ファイルに保存し、再インポートして変換し直して元の値を取得することはできません。これは学習プロジェクトであることを忘れないでください。これは私がこれまでに行っていることです

private string SerializeToString(string obj)
    {
        if (obj == null)
            return null;

        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
        MemoryStream ms = new MemoryStream();
        bf.Serialize(ms, obj);
        byte[] Array = ms.ToArray();
//This is where I create the txt file and write to it
            File.OpenWrite(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)     + "\\Text.txt")
            .Write(Array, 0, Array.Length);



        ms.Close();
        return Convert.ToBase64String(Array);
    }

        private void txtCheck_Click(object sender, RoutedEventArgs e)
    {
//I uploaded the file to drop box and can successfully download it but can not figure out
//how to get the original value out of it..
        string Url = "http://dl.dropbox.com/u/62170850/Text.txt";
        WebClient webClient = new WebClient();
        //webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
        //webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
        byte[] myDataBuffer = webClient.DownloadData(new Uri(Url));
        string s = Convert.ToBase64String(myDataBuffer);
    }
4

1 に答える 1

0

webClient.DownloadStringを使用し、FromBase64String逆シリアル化の前にダウンロードした文字列を呼び出しでバイト配列に戻すことを忘れないでください。

于 2013-03-15T01:02:20.597 に答える