zoukankan      html  css  js  c++  java
  • WebClient类--上传文件

     #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: est.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

  • 相关阅读:
    数据库-第六章 关系数据理论-6.2.1 函数依赖
    数据库-第六章 关系数据理论-6.1 问题的提出
    编译原理-第四章 语法分析-4.4 自顶向下的语法分析
    计算机组成及系统结构-第五章 指令系统
    编译原理-第四章 语法分析-4.3 设计文法
    Java数据结构之堆和优先队列
    进程与线程杂谈
    Java的多态浅谈
    Java的自定义注解使用实例
    elasticsearch6.6.2在Centos6.9的安装
  • 原文地址:https://www.cnblogs.com/chenxiulou/p/4624603.html
Copyright © 2011-2022 走看看