开发者

How to read a text file from a Uri, and save it, using Silverlight/ C#?

i want to read a file by its Uri, and ask the user to store the file. This has to be done using Silverlight.

Ive tried the following, and it didnt work.开发者_Python百科.

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();

            }
        }


As from my comment, client.OpenWriteAsync should be client.OpenReadAsync ( yes this is a indiscriminated way of gaining some points :) )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜