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> ......
发送端以163为例
一、asp.net版 using System.Web.Mail; //命名空间引用
c#
MailMessage mail = new MailMessage();
mail.To = "shadow103@qq.com"; //接受人的邮箱
& ......
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 ......
asp.net 获取html控件的值的代码如下:
WebForm1.aspx:
< INPUT ID="TXT" TYPE="TEXT" RUNAT="SERVER" VALUE="AAAAAA">
< INPUT TYPE="BUTTON" RUNAT="SERVER" VALUE="BTNTEST" ID="BUTTON1"&nb ......