ASP.Net中的几种文件下载方法
//TransmitFile实现下载
protected void Button1_Click(object sender, EventArgs e)
{
/*
微软为Response对象提供了一个新的方法TransmitFile来解决使用Response.BinaryWrite
下载超过400mb的文件时导致Aspnet_wp.exe进程回收而无法成功下载的问题。
代码如下:
*/
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=z.zip");
string filename = Server.MapPath("DownLoad/z.zip");
Response.TransmitFile(filename);
}
//WriteFile实现下载
protected void Button2_Click(object sender, EventArgs e)
{
/*
using System.IO;
*/
string fileName = "asd.txt";//客户端保存的文件名
string filePath = Server.MapPath("DownLoad/aaa.txt");//路径
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Lengt
相关文档:
1、添加Web.config, < system.web>< /system.web>中添加< customErrors mode="On"
defaultRedirect="ApplicationErroy.aspx" >< /customErrors>节点,
2、添加Global.asax文件,找到Application_Error事件,加入以下代码:
//这是添加了一个全局应用程 ......
好多人对相对路径与绝对路径老是混淆记不清楚,我从整理了一下,希望对大家的认识有帮助。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1.Request.ApplicationPath->当前应用的目录
Jsp中, ApplicationPath指的是当前的application(应用程序)的目录,ASP.NET中也是这个意思。
对应 ......
1) 多选效果
多选效果完全可以通过脚本进行实现。我们知道,多选的控件最终生成一个input的HTML标签,它的类型是checkbox。由于这个页面中只有一组复选框,所以实现起来也比较方便:我们可以遍历所有的input标签,对比其type属性是不是checkbox,如果是checkbox,就给它设置相应的选中状态就行了。
代码如下:
<scri ......
SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
SqlCommand cmdAdd = new SqlCommand( "Community_Disc ......
下载 ADO.NET Driver for MySQLMySql.Data.dll
安装后,在安装目录下面找到Assemblies
文件夹,找到 MySql.Data.dll
(此文件是.Net访问MySQL数据库的一个驱动,完全ADO.NET数据访问模式,由MySQL官方提供,有多个版本可选择。)
学习的一个链接:http://www.cnblogs.com/wcfgroup/articles/1242256.html
创建一个 ......