基本信息
源码名称:ASP.NET文件的上传下载
源码大小:11.79M
文件格式:.zip
开发语言:C#
更新时间:2020-01-02
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = FileUpload1.FileName;//获取上传的文件名
this.TextBox1.Text = fileName;
//获取上传文件的后缀名
String filefix = fileName.Substring(fileName.LastIndexOf('.') 1).ToLower();
if (filefix!="png"&&filefix!="jpg"&&filefix!="jpeg"&&filefix!="gif")
{
FileUpload1.SaveAs(Server.MapPath(".") "//UploadPic//" fileName);
this.ImgPic.ImageUrl = "";
this.lblMessage.Text = "文件上传成功!";
}
else
{
FileUpload1.SaveAs(Server.MapPath(".") "//UploadPic//" fileName);
this.ImgPic.ImageUrl = "~/UploadPic/" fileName;
this.lblMessage.Text = "图片上传成功!";
}
}
}
protected void btnDownload_Click(object sender, EventArgs e)
{
string name = this.TextBox1.Text;
//MessageBox.Show(name);
string filename = Server.MapPath(".") "/UploadPic/" name;
FileInfo fileinfo = new FileInfo(filename);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Disposition", "attachment;filename=" Server.UrlEncode(fileinfo.Name));
Response.AddHeader("Content-Length", fileinfo.Length.ToString());
Response.ContentType = "application/x-bittorrent";
Response.WriteFile(fileinfo.FullName);
Response.End();
//Response.ContentType = "application/x-zip-compressed";
//Response.AddHeader("Content-Disposition", "attachment;filename=" name);
//Response.TransmitFile(filename);
}
}
}