<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="FileUpload1" runat="server" /><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传文件" /> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="下载文件" /></div> </form> </body> </html> 自己给自己留点资料 using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string str = ""; if (FileUpload1.HasFile) { try { str += "上传文件名:" + FileUpload1.FileName; str += "<br/>文件类型:" + FileUpload1.PostedFile.ContentType; str += "<br/>文件大小:" + FileUpload1.PostedFile.ContentLength; FileUpload1.SaveAs(Server.MapPath("~/Upload/") + FileUpload1.FileName); } catch (Exception ex) { str += "上传文件失败" + ex.Message; } } else { str += "无文件上传"; } Response.Write(str); } protected void Button2_Click(object sender, EventArgs e) { Download(Server.MapPath("~/Download/")+"常用数据绑定控件的用法.txt"); } public void Download(string FullName) { FileInfo DownFile = new FileInfo(FullName); Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownFile.FullName, System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", DownFile.Length.ToString()); Response.WriteFile(DownFile.FullName); Response.Flush(); Response.End(); } }