下载与更新

private void DownLoadFile()
  {
   
   
   try
   {
    
    //    string ophos = "&OPHOS=OPHOS";
    //    string opcd = "&OPCD=OPCD";
    string ophos = "";
    string opcd = "";
    string FileURL = ImageURL + fileName + ophos + opcd;
    if(!Directory.Exists(Application.StartupPath+" //update"))
    {
     Directory.CreateDirectory(Application.StartupPath+" //update");
    }
    pathName = Application.StartupPath+" //update";
    HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(FileURL);
    hwr.Timeout = 30000;
    this.label1.Text = "正在连接。。。";
    HttpWebResponse hwrs = (HttpWebResponse)hwr.GetResponse();
    Stream receiveStream = hwrs.GetResponseStream();
    this.label1.Text = "已连接,正在下载更新文件("+fileName+"),请稍侯。。。";
    MemoryStream ms = new MemoryStream();
    byte[] bt;
    while(true)
    {
     bt = new byte[1024];
     int cnt = receiveStream.Read(bt, 0, 1024);
     ms.Write(bt,0,cnt);
     if (cnt == 0)
      break;
    }
    byte[] byteImage = new byte[ms.Length];
    byteImage = ms.ToArray();
    FileStream outStream = new FileStream(pathName.Trim() + "//" + fileName.Trim() , FileMode.Create);
    outStream.Write(byteImage,0,(int)byteImage.Length);
    outStream.Flush();
    outStream.Close();
    this.label1.Text = "完成下栽,是否现在更新?";
    this.button1.Visible = true;
    this.button2.Visible = true;
   }
   catch(Exception ex)
   {
    this.label1.Text = ex.ToString();
   }
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值