ASP.NETÎļþÏÂÔغ¯ÊýʹÓÃdzÎö
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;
}
ÕâÑù¾ÍʵÏÖÁËÎļþÏÂ
Ïà¹ØÎĵµ£º
ÔÚWeb±à³Ì¹ý³ÌÖУ¬´æÔÚןܶలȫÒþ»¼¡£±ÈÈçÔÚÒÔÇ°µÄASP°æ±¾ÖУ¬CookieΪ·ÃÎÊÕߺͱà³ÌÕ߶¼ÌṩÁË·½±ã£¬²¢Ã»ÓÐÌṩ¼ÓÃܵŦÄÜ¡£´ò¿ªIEä¯ÀÀÆ÷£¬Ñ¡Ôñ“¹¤¾ß”²Ëµ¥ÀïµÄ“InternetÑ¡Ï¬È»ºóÔÚµ¯³öµÄ¶Ô»°¿òÀïµ¥»÷“ÉèÖÔ°´Å¥£¬Ñ¡Ôñ“²é¿´Îļþ”°´Å¥£¬ÔÚµ¯³öµÄ´°¿ÚÖУ¬¾Í»áÏÔʾӲÅÌÀï ......
ÔÚÈí¼þÒµÀï´Ó³ÌÐòÔ±³öÉíµÄ£¬Ç§Íò²»Òª°ÑÄã×Ô¼ºµÄ±¾Ðжªµô¡£ÎÒ˵µÄ±¾ÐÐÊǼ¼Êõ¡£ËäÈ»ÔÚÖйú£¬ËÀ×êÑм¼ÊõûÓгö·£¬»°ËäÕâô˵£¬µ«¼¼Êõ³öÉíµÄ¹ÜÀíÕߣ¬¾ø¶ÔÅ£ÓÚ´¿´â¸ã¹ÜÀíµÄÖ½ÉÏ̸±ø£¨µ±È»ÅųýÓàÊÀάÕâÑùµÄÈË£¬Å£²æ²æµÄMBA²©Ê¿)¡£²©¿ÍÔ°ÀïÓÐºÜ¶à“³ÌÐòÔ±->¼Ü¹¹Ê¦->¹ÜÀíÕß”µÄ°ñÑù¡£
×î½üºÜ¾ÃûÀ´Ô°×ÓÀïд²©¿ÍÁË ......
´ËľÂíдÁËÒ»¶Îʱ¼äÁË,д³öÀ´¾õµÃ×Ô¼º¶Ô.netÓÐÁ˸ü¶àµÄÈÏʶ,µ±È»Ö÷ÒªÊÇѧϰµ½Á˺ܶà֪ʶ.ËùÒÔ¸öÈ˸оõѧϰ±à³Ì×îºÃµÄ;¾¶¾ÍÊÇ´ø×ÅÏîĿȥѧϰ,ÅäºÏ°Ù¶È,googleÈ¥½â¾öÎÊÌâ. ºÇºÇ ÅÅ°æ±È½Ï³óª,¹¦ÄÜʵÓþͺÃ. ºÃÁË,ÏÖÔÚ·¢²¼´ËľÂí
1.µÇ½½çÃæ:
2. Ö÷Ìå½çÃæ
3. ¸÷¹¦ÄÜÄ£¿é
°Ù¶ÈÏÂÔصØÖ·: http://www.baidu.com/s? ......
BulletedList ¿Ø¼þ´´½¨Ò»¸öÎÞÐò»òÓÐÐò£¨±àºÅµÄ£©µÄÏîÁÐ±í£¬ËüÃÇ·Ö±ð³ÊÏÖΪ HTML ul »ò ol ÔªËØ¡£
1¡¢·½°¸
BulletedList ¿Ø¼þÓÃÓÚÖ´ÐÐÒÔϲÙ×÷£º
·Ö¸¶¨ÁбíÖÐÏî¡¢ÏîÄ¿·ûºÅ»ò±àºÅµÄÍâ¹Û¡£
·¾²Ì¬¶¨ÒåÁбíÏî»òͨ¹ý½«¿Ø¼þ°ó¶¨µ½Êý¾ÝÀ´¶¨ÒåÁбíÏî¡£
·ÏìÓ¦Óû ......
protected void Button1_Click(object sender, EventArgs e)
{
string fullName = this.File1.PostedFile.FileName;//»ñÈ¡ÉÏ´«ÎļþµÄȫ·¾¶
string size = th ......