91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

asp.net文件下載

發布時間:2020-03-26 11:50:29 來源:網絡 閱讀:353 作者:Ctansuozhe 欄目:編程語言
 
switch (Convert.ToInt32(Request["type"]))
{
                               //流方式下載 方法一
case 1:
string filename = "123.pdf";
string filepath = Server.MapPath("upload/123.pdf");
FileStream fs = new FileStream(filepath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "p_w_upload; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.Default));
Response.BinaryWrite(bytes);
Response.Flush();
break;
case 2://方法2
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "p_w_upload;filename=z.zip");
string filename2 = Server.MapPath("upload/aaa.zip");
Response.TransmitFile(filename2);
break;
case 3://方法三
string fileName = "123.pdf";
string filePath = Server.MapPath("upload/123.pdf");
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "p_w_upload;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
break;
case 4://分塊下載,方法四
string fileName4 = "123.pdf";
string filePath5 = Server.MapPath("upload/123.pdf");
 
System.IO.FileInfo fileInfo4 = new System.IO.FileInfo(filePath5);
 
if (fileInfo4.Exists == true)
{
const long ChunkSize = 1024000;//每次讀取100K
byte[] buffer = new byte[ChunkSize];
 
Response.Clear();
System.IO.FileStream iStream = System.IO.File.OpenRead(filePath5);
long dataLengthToRead = iStream.Length;//獲取文件長度
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "p_w_upload; filename=" + HttpUtility.UrlEncode(fileName4));
while (dataLengthToRead > 0 && Response.IsClientConnected)
{
int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(ChunkSize));
Response.OutputStream.Write(buffer, 0, lengthRead);
Response.Flush();
dataLengthToRead = dataLengthToRead - lengthRead;
}
Response.Close();
}
break;
default:
Response.Write("ddd");
break;
}
Response.End();
 
 
下載文件方法封裝,怎樣根據文件的擴展名下載文件(如沒有擴展名,文件打開有可能出現亂碼)
void DownloadFile(string filename)
{
 
string saveFileName = "123.xls";
int intStart = filename.LastIndexOf("\\") + 1;
saveFileName = filename.Substring(intStart, filename.Length - intStart);
 
System.IO.FileInfo fi = new System.IO.FileInfo(filename);
string fileextname = fi.Extension;
string DEFAULT_CONTENT_TYPE = "application/unknown";
RegistryKey regkey, fileextkey;
string filecontenttype;
try
{
regkey = Registry.ClassesRoot;
fileextkey = regkey.OpenSubKey(fileextname);
filecontenttype = fileextkey.GetValue("Content Type", DEFAULT_CONTENT_TYPE).ToString();
}
catch
{
filecontenttype = DEFAULT_CONTENT_TYPE;
}
 
 
Response.Clear();
Response.Charset = "utf-8";
Response.Buffer = true;
this.EnableViewState = false;
Response.ContentEncoding = System.Text.Encoding.UTF8;
 
Response.AppendHeader("Content-Disposition", "p_w_upload;filename=" + saveFileName);
Response.ContentType = filecontenttype;
 
Response.WriteFile(filename);
Response.Flush();
Response.Close();
 
Response.End();
}
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

哈密市| 大石桥市| 扶沟县| 北京市| 三亚市| 广饶县| 麟游县| 米泉市| 陵川县| 库尔勒市| 玛沁县| 南投县| 泸溪县| 成武县| 福贡县| 菏泽市| 长岭县| 邢台县| 屯昌县| 惠安县| 始兴县| 铜川市| 滦平县| 松原市| 徐水县| 静海县| 肇源县| 常熟市| 庐江县| 望都县| 雅江县| 慈利县| 汉寿县| 如皋市| 宽甸| 菏泽市| 望江县| 东宁县| 台江县| 永顺县| 东丽区|