Form1.cs
上传用户:jsz11269
上传日期:2017-01-14
资源大小:450k
文件大小:2k
源码类别:

Email服务器

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Net;
  9. using System.IO;
  10. namespace UseWebClient
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private void btnGet_Click(object sender, EventArgs e)
  19.         {
  20.             try
  21.             {
  22.                 WebClient client = new WebClient();
  23.                 //client.BaseAddress = "shaozhd";
  24.                 Stream response = client.OpenRead(tbURL.Text);
  25.                 tbContent.Text = "";
  26.                 int nByteData;
  27.                 do
  28.                 {
  29.                     nByteData = response.ReadByte();
  30.                     if (nByteData > 0)
  31.                         tbContent.Text += Convert.ToChar(nByteData);
  32.                 } while (nByteData > 0);
  33.                 response.Close();
  34.             }
  35.             catch (Exception ex)
  36.             {
  37.                 MessageBox.Show(ex.Message.ToString());
  38.             }
  39.         }
  40.         private void btnDownload_Click(object sender, EventArgs e)
  41.         {
  42.             try
  43.             {
  44.                 WebClient client = new WebClient();
  45.                 FolderBrowserDialog dlg = new FolderBrowserDialog();
  46.                 if (dlg.ShowDialog() == DialogResult.OK)
  47.                 {
  48.                     string strDes = dlg.SelectedPath + Path.GetFileName(tbAddress.Text);
  49.                     client.DownloadFile(tbAddress.Text, strDes);
  50.                     MessageBox.Show("文件下载到:"+ strDes) ;
  51.                 }
  52.             }
  53.             catch (Exception ex)
  54.             {
  55.                 MessageBox.Show(ex.Message.ToString());
  56.             }
  57.         }
  58.     }
  59. }