开发者

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

开发者 https://www.devze.com 2023-03-06 22:12 出处:网络
i want to read a file by its Uri, and ask the user to store the file. This has to be done using Silverlight.

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

精彩评论

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