Silverlight专题(10)-WCF通信(2)
2008-10-27 11:49:08 来源:WEB开发网a.选择上传文件对话框的实现如下
1 public void uploadBtn_Click(object sender, RoutedEventArgs e)
2 {
3 OpenFileDialog ofd = new OpenFileDialog();
4 ofd.Filter = "JPG Files|*.jpg|PNG Files|*.png";
5 ofd.Multiselect = false;
6
7 if ((bool)ofd.ShowDialog())
8 {
9 this.pb.Visibility = Visibility.Visible;
10 this.img.Opacity = 0;
11 dataSent = 0;
12 stream = ofd.File.OpenRead();
13 dataLength = stream.Length;
14 if (dataLength > 16384)
15 {
16 firstChunk = true;
17 lastChunk = false;
18 fileName = ofd.File.Name;
19 byte[] buffer = new byte[4 * 4096];
20 int read = stream.Read(buffer, 0, buffer.Length);
21 dataSent += read;
22 if (read != 0)
23 {
24 if (dataSent == dataLength)
25 lastChunk = true;
26 client.UploadImgAsync(fileName, buffer, firstChunk, lastChunk);
27 firstChunk = false;
28 }
29 }
30
31 else
32 {
33 MessageBox.Show("The upload file is too small!");
34 }
35 }
36 }
Tags:Silverlight 专题 WCF
编辑录入:爽爽 [复制链接] [打 印]- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››Silverlight for Symbian
- ››专题功能优化 for V7.5 SP3 优化包
- ››专题css详解
- ››Silverlight3系列(四)数据绑定 Data Binding 1
- ››WCF技术剖析之三十:一个很有用的WCF调用编程技巧...
- ››专题功能优化 for v7.5 sp3
更多精彩
赞助商链接