基本信息
源码名称:asp.net 文件下载 示例源码
源码大小:22.32M
文件格式:.zip
开发语言:ASP
更新时间:2019-05-30
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
string path = Server.MapPath("File/") "DOT.GIF";
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
//Response.Clear();
//Response.ClearHeaders();
//Response.Buffer = true;
//Response.AddHeader("Content-Length", fi.Length.ToString());
//Response.ContentType = "application/application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" HttpUtility.UrlEncode(fi.Name));
Response.WriteFile(fi.FullName);
//Response.End();
//Response.Flush();
//Response.Clear();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.PostedFile.FileName == "")
{
Label1.Text = "要上传的文件不允许为空!";
return;
}
else
{
string filepath = FileUpload1.PostedFile.FileName;//取文件路径
string filename = filepath.Substring(filepath.LastIndexOf("\\") 1);//取文件名
string serverpath = Server.MapPath("File/") filename;//合成上传路径
FileUpload1.PostedFile.SaveAs(serverpath);//上传文件
Label1.Text = "上传成功!";
}
}
catch (Exception error)
{
Label1.Text = "处理发生错误!原因:" error.ToString();
}
}
}