从silverlight应用程序操作txt文件?

时间:2013-03-13 10:29:46

标签: c# silverlight asynchronous text-files webclient

我正在尝试修改位于我服务器上的txt文件,因为我正在使用此代码:

 WebClient webClientvent = new WebClient();
                webClientvent.OpenWriteCompleted += new OpenWriteCompletedEventHandler(Readvent);
                webClientvent.OpenWriteAsync(new Uri("/v.txt", UriKind.Relative));

private void Readvent(object sender, OpenWriteCompletedEventArgs e)
        {


            if (e.Error != null) {
                MessageBox.Show(e.Error.ToString());
            }
            WebClient webClient = (WebClient)sender;
            webClient.OpenWriteCompleted -= this.Readvent;
            Stream stream = e.Result;
            StreamReader monStreamReader = new StreamReader(stream);


            try
            {


                StreamWriter monStreamWriter = new StreamWriter(stream);


                monStreamWriter.WriteLine("first");
                monStreamWriter.WriteLine("second");


                monStreamWriter.Close();

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            } 

            }

但是,这个Txt文件中没有写任何内容,我错过了什么?

1 个答案:

答案 0 :(得分:0)

处理WebClient.UploadProgressChanged Event以及您还需要上传数据

webClientvent.UploadStringAsync();