在 ASP.NET 中使用 file uploader 实现文件的上传与下载:
File Upload Code
string FilePath = "";
string[] a = new string[1];
string fileName = "";
string FullName = "";
if (FileUploader.FileName.Length > 0)
{
a = FileUploader.FileName.Split('.');
fileName = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
FilePath = Server.MapPath(@"~/SavedFolder");
Fup1.SaveAs(FilePath + @"/" + fileName);
FullName = FilePath + @"/" + fileName;
// Database Saved Code
}
File Download Code
string filename = "filename from Database";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
string aaa = Server.MapPath("~/SavedFolder/" + filename);
Response.TransmitFile(Server.MapPath("~/SavedFolder/" + filename));
Response.End();
原文:http://www.codeproject.com/Tips/185886/File-Upload-and-Download-in-ASP-NET.aspx