易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET文件下载函数使用

 ASP.NET文件下载函数使用是什么情况呢?在你的Page_Load中添加这样的代码:
Page.Response.Clear();
bool success = ResponseFile(Page.Request, Page.Response, "目的文件名称", @"源文件路径", 1024000);
if (!success) Response.Write("下载文件出错!"); Page.Response.End();
ASP.NET文件下载函数代码为:
public static bool ResponseFile(HttpRequest _Request,HttpResponse _Response,string _fileName,string _fullPath, long _speed) {
try
{
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes"
);
_Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0; double pack = 10240;
//10K bytes
//int sleep = 200;
//每秒5次 即5*10K bytes每秒 int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] {'=', '-'});
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0) {
//Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition","attachment; filename=" + HttpUtility.UrlEncode(_fileName,System.Text.Encoding.UTF8) ); br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int) Math.Floor((fileLength - startBytes) / pack) + 1;
for (int i = 0; i < maxCount; i++) { if (_Response.IsClientConnected) { _Response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString()))); Thread.Sleep(sleep);
} else { i=maxCount;
}
} }
catch
{
return false;
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
return false;
}
return true;
}
这样就实现了


相关文档:

ASP.NET常用代码

1. 打开新的窗口并传送参数:
 
传送参数:
response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')</script>")
接收参数:
string a = Request.QueryString("id");
string b = Request.QueryString("id1");
2.为按钮添加对话框
Button1.Attribut ......

ASP.NET(c#)常用类函数

 
常用函数系列:
public static string Get_ClientIP() 得到客户端IP
public static string Get_CMac(string IP) 得到客户端 CMac 地址
public static string RequestF(string xPName,string xPType,int xLenDef) 安全接收数据系列
public static string Show_Cont(string xStr) 过滤显示字串
public static str ......

ASP.NET笔试题目

 ADO.NET程序设计模拟题(共206题)
1
ADO.NET 模型中的下列哪些对象属于Connected 对象
A. Connection
B. DataAdapter
C. DataReader
D. DataSet
正确答案:ABC
2
在ADO.NET 中,为访问DataTable 对象从数据源提取的数据行.可使用DataTable 对象的_______属性.
A. Rows
B. Columns
C. Constraints
D. Data ......

asp.net从sql server2005中查询数据

 首先要添加
using System.Data;
using System.Data.SqlClient;    
接下来:
          SqlConnection conn = new SqlConnection("server=QLPC\\SQL2005;uid=sa;pwd=(你的密码);database=(你的数据表)");     &n ......

启动asp.net页面缓存(加快页面访问速度)

 启动页面缓存,代码如下:
<%OutputCache Duration="60" VaryByParam="*"%>
 说明:
Duration必需属性。页面被缓存旱,以秒为单位,且必须是整数。
Location 指定应输出进行缓存的位置。参数是以下选项之一:Any,Client,Downstream,None,Server,ServerAndClient
VaryByParam 必需属性。Request中变量 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号