博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET文件的上传下载提交分页
阅读量:5878 次
发布时间:2019-06-19

本文共 4323 字,大约阅读时间需要 14 分钟。

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="DownLoadPage.aspx.cs" Inherits="WebApplication2.DownLoadPage" %>

下载压缩文件

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 WebApplication2{    public partial class DownLoadPage : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        //下载        protected void Button1_Click(object sender, EventArgs e)        {            //用代码将文件发送给浏览器            //可以先检测用户的权限或积分再做文件的发送.....            //指定我接下来给你发送的是什么类型文件            Response.ContentType = "application/zip";            //指定头信息,告诉浏览器是一个附件            Response.AddHeader("content-disposition","attchment;filename=aaa.zip");            //1.一次将文件放到内存中,在发送的            //Response.WriteFile("/IMBA_3.86b_ai.zip");            //2.用流变读取文件边发送            FileStream fs = new FileStream(Server.MapPath("/IMBA_3.86b_ai.zip"), FileMode.Open, FileAccess.Read, FileShare.Read);            Stream st= Response.OutputStream;            //将fs内容读取写入到st            byte[] buffer = new byte[102400];            while (true)            {                int len = fs.Read(buffer, 0, buffer.Length);                if (len == 0) break;                st.Write(buffer,0,len);                Response.Flush();            } fs.Close();            Response.End();        }    }}

 

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Goods.aspx.cs" Inherits="WebApplication2.Goods" %><%@ Register src="NotNullTextBox.ascx" tagname="NotNullTextBox" tagprefix="uc1" %><%@ Register assembly="ServerControl1" namespace="ServerControl1" tagprefix="cc1" %><%@ Register src="PageApart.ascx" tagname="PageApart" tagprefix="uc2" %>
这里放商品信息
用户名:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace WebApplication2{    public partial class Goods : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {                    }        //提交        protected void Button2_Click(object sender, EventArgs e)        {            //NotNullTextBox nb = new NotNullTextBox();            //TextBox c = NotNullTextBox1.FindControl("TextBox1") as TextBox;//找到输入框            //Response.Write(c.Text);            string x = NotNullTextBox1.Text;            Response.Write(x);//利用属性的封装        }    }}
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="UpLoadPage.aspx.cs" Inherits="WebApplication2.UpLoadPage" %>

 
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 WebApplication2{    public partial class UpLoadPage : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        //上传        protected void Button1_Click(object sender, EventArgs e)        {            //准备文件名            string fileName = "UpLoad/";            string type = Path.GetExtension(FileUpload1.FileName);            fileName += DateTime.Now.Ticks + type;            FileUpload1.SaveAs(Server.MapPath(fileName));            //1.将上传文件缓存到内存,在将内存一次性放到磁盘(耗内存)            FileUpload1.SaveAs(Server.MapPath(fileName));            //2.用流的方式,边上传边接受,接受到的内容写入到磁盘文件中            FileStream fs = new FileStream(Server.MapPath(fileName),FileMode.Create,FileAccess.Write,FileShare.Read);            HttpPostedFile hpf = FileUpload1.PostedFile;            Stream st = hpf.InputStream;//上传的文件的文件流            //st  读,读取到的写入到fs里            byte[] buffer = new byte[102400];            while (true)            {                int len = st.Read(buffer,0,buffer.Length);                if (len == 0) break;                fs.Write(buffer,0,len);            }            st.Close();            fs.Close();            Response.Write("上传成功");        }    }}

 

 

 

转载于:https://www.cnblogs.com/xiaz/p/5242983.html

你可能感兴趣的文章
How to use Git and svn together
查看>>
位运算符与逻辑运算符在操作逻辑型数据时的区别
查看>>
【WPF】控件使用-宽度自动适应窗口大小
查看>>
C++中的对象的赋值和复制
查看>>
Python day2
查看>>
当我们谈论CloudTable时究竟在谈论什么?
查看>>
map和flatMap
查看>>
Vue2.0 vue-source.js jsonp demo vue跨域请求
查看>>
CF865D Buy Low Sell High
查看>>
解决页面使用ifrmae后,在session失效后登录页面在子页面中显示(子窗体出现父窗体)...
查看>>
例子:两个列表之间移动数据
查看>>
EF Core反向导航属性解决多对一关系
查看>>
数据流图试题
查看>>
多媒体基础-试题01
查看>>
Tesseract-ocr c#文字识别简单入门
查看>>
得到CPU 及硬盘序列号(网友给的,未证实)
查看>>
js-图片img转base64格式
查看>>
各种开源资料汇总
查看>>
RequireJs加载Codemirror,配合AngularJS的坑
查看>>
技术跟产品杂谈
查看>>