如何使用Silverlight / C#从Uri读取文本文件并保存?

时间:2011-05-19 17:39:11

标签: c# silverlight

我想通过其Uri读取文件,并要求用户存储该文件。这必须使用Silverlight完成。

我尝试过以下内容,但它没有用。

client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);

private void Build_Log_Click(object sender, RoutedEventArgs e)
      {
          Uri uri = new Uri("http:***.log");
          client.OpenWriteAsync(uri);
      }

private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            bool? result = textDialog.ShowDialog();
            if (result == true)
            {

                var text = e.Result;
                System.IO.Stream fileStream = textDialog.OpenFile();
                StreamWriter sw = new System.IO.StreamWriter(fileStream);
                sw.Write(text);
                sw.Flush();
                sw.Close();

            }
        }

1 个答案:

答案 0 :(得分:1)

从我的评论中,client.OpenWriteAsync应该是client.OpenReadAsync(是的,这是获得一些积分的不分青红皂白的方式:))