c# 文件上传下载
1. 介绍
C#文件上传下载用WebClient类实现
微软官方使用Demo
架构为B/S
模板
服务器: WebForm
客户端:ConsoleApplication
2. 代码
2.1 客户端
解决方案:
WebClientOper.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace WebClientOperation
{
class WebClientOper
{
public bool UploadFile(string address, string fileName)
{
if (!File.Exists(fileName))
return false;
using (WebClient client = new WebClient())
{
client.UploadProgressChanged += Client_UploadProgressChanged; ;
client.UploadFileCompleted += Client_UploadFileCompleted; ;
client.UploadFileAsync(new Uri(address), fileName);
Console.ReadKey();
}