asp.net 用流的方式下载文件
//以下代码根据别人文章和自己整理
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 DownfFile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// WriteFile下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
string name ="DreamweaverCS3简体中文免激活绿色版.rar";
string path =Server.MapPath("DreamweaverCS3简体中文免激活绿色版.rar");
FileInfo fileinfo = new FileInfo(path);
long size = fileinfo.Length;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + name);
Response.AppendHeader("Content-Length", size.ToString());
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.ContentEncoding = System.Text.Encoding.UTF8;//GetEncoding("gb2312");
Response.WriteFile(path,0,size);
Response.Flush();
Response.End();
}
/// <summary>
/// 使用OutputStream.Write分块下载文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button2_Click(object sender, EventArgs e)
{
string fileName = HttpContext.Current.Server.UrlEncode("DreamweaverCS3简体中文免激活绿色版.rar");
string filePath = HttpContext.Current.Server.MapPath("DreamweaverCS3简体中文免激活绿色版.rar");
//如果要写类的话用HttpResponse h
相关文档:
<system.web>
<!--********出错页的设定********-->
<customErrors mode="On" defaultRedirect="~/Error.htm"> </customErrors> ......
1、双击一个数据源控件,将要存储profile的数据库作为数据源加入控件(这个步骤没什么用,只是为了方便大家用控件建立连接,这样不容易出错),建立好之后将design页面的数据源控件删除,你会发现在web.config里还是有一条连接语句,不要删除,我们下面将用到它,如: <connectionStrings>
<add ......
IIS 7
IIS7自身有对MVC的支持,部署方法同其他web application基本相同,需要注意的是,mvc 2.0 application在Handler Mappings里面会有MvcHttpHandler,如图:
我使用的是.net 4.0,我看了其他.net 2.0 的web appliation下的Handler Mappings都没有这个handler maping。
注意:.net 3.5以下(包括)的web application p ......
本文将探讨asp.net下实现文件上穿进度条的方法。
一般情况下,要实现上传进度条首先要实现上传文件分块读取,而默认情况下,iis将直接把上传的文件一次读入到内存中,所以本处的难点在于拦截iis的文件上传过程,转而自己的实现方式。所以,我们可以实现一个IHttpModule来处理上传过程。具体的过程是Application_BeginReque ......