分享

WebClient类--上传文件

 _明心见性_ 2017-11-25
#region 把本地文件上传到指定uri
2         /// <summary>
3         /// 把本地文件上传到指定uri
4         /// </summary>
5         /// <param name="sender"></param>
6         /// <param name="e"></param>
7         private void button2_Click(object sender, EventArgs e)
8         {
9             WebClient wc = new WebClient();
10             string targetPath = "http://127.0.0.1/rss/Data Configuration.zip";
11             string sourcePath = "d:\\Data Configuration.zip";
12             this.label1.Text = string.Format("uploading {0} to {1}", targetPath, sourcePath);
13             byte[] bt = wc.UploadFile(targetPath, "PUT", sourcePath);
14             MessageBox.Show("OK");
15         }
16         #endregion
17
18
19         #region 把数据缓冲区上载到指定资源
20         /// <summary>
21         /// 把数据缓冲区上载到指定资源
22         /// </summary>
23         /// <param name="sender"></param>
24         /// <param name="e"></param>
25         private void button3_Click(object sender, EventArgs e)
26         {
27             WebClient wc = new WebClient();
28             string targetPath = "http://127.0.0.1/rss/kaifeng.jpg";
29             string sourcePath = @"C:\test.jpg";
30             FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read);
31             byte[] bt = new byte[fs.Length];
32             fs.Read(bt, 0, bt.Length);
33             wc.UploadData(targetPath, "PUT", bt);
34         }
35         #endregion

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多