silverlight不支持本地文件创建等相关操作,上传文件时可以先把文件读入字节数组,然后调用web服务实现上传。 具体实现如下: silverlight端代码: private void button1_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog().Value) { // 选择上传的文件 FileInfo file = dialog.File; Stream stream = file.OpenRead(); stream.Position = 0; byte[] buffer = new byte[stream.Length + 1]; //将文件读入字节数组 stream.Read(buffer, 0, buffer.Length); String fileExtention = file.Extension; //调用服务上传 ServiceReference1.UploadFileSoapClient upfile = new UploadFileSoapClient(); upfile.UploadfileAsync(buffer, fileExtention); upfile.UploadfileCompleted += new EventHandler<UploadfileCompletedEventArgs>(upfile_UploadfileCompleted); } else { MessageBox.Show("请选择文件!"); } } void upfile_UploadfileCompleted(object sender, UploadfileCompletedEventArgs e) { MessageBox.Show("上传成功!"); } webservice代码: [WebMethod] public int Uploadfile(byte[] FileByte, string FileExtention) { //文件存放路径 string filepath = string.Format(@"D:/example{0}", FileExtention); //如果文件已经存在则删除 if (File.Exists(filepath)) File.Delete(filepath); //创建文件流实例,用于写入文件 FileStream stream = new FileStream(filepath, FileMode.CreateNew); //写入文件 stream.Write(FileByte, 0, FileByte.Length); stream.Close(); return FileByte.Length; }