从silverlight应用程序操作txt文件

本文关键字:txt 文件 操作 应用程序 silverlight | 更新日期: 2023-09-27 18:03:52

我正在尝试修改位于我的服务器上的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文件,我错过了什么?

从silverlight应用程序操作txt文件

处理WebClient。UploadProgressChanged事件以及你需要上传的数据

webClientvent.UploadStringAsync();