重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
下載,直接通過url讀取文件,然后Response.OutputStream.Write()數據
成都創新互聯公司-專業網站定制、快速模板網站建設、高性價比平南網站開發、企業建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式平南網站制作公司更省心,省錢,快速模板網站建設找我們,業務覆蓋平南地區。費用合理售后完善,十年實體公司更值得信賴。
下面提供個下載的靜態方法,是C#的,供參考:
///?summary
///?下載文件
///?/summary
///?param?name="fileName"下載的文件名稱(包括擴展名)/param
///?param?name="filePath"下載文件的絕對路徑/param
public?static?void?DownFile(string?fileName,?string?filePath)
{
//打開要下載的文件,并把該文件存放在FileStream中????????????????
System.IO.FileStream?Reader?=?System.IO.File.OpenRead(filePath);
//文件傳送的剩余字節數:初始值為文件的總大小????????????????
long?Length?=?Reader.Length;
HttpContext.Current.Response.Buffer?=?false;
HttpContext.Current.Response.AddHeader("Connection",?"Keep-Alive");
HttpContext.Current.Response.ContentType?=?"application/octet-stream";
HttpContext.Current.Response.Charset?=?"utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition",?"attachment;?filename="?+?System.Web.HttpUtility.UrlEncode(fileName));
HttpContext.Current.Response.AddHeader("Content-Length",?Length.ToString());
byte[]?Buffer?=?new?Byte[10000];//存放欲發送數據的緩沖區????????????????
int?ByteToRead;?//每次實際讀取的字節數???????????????
while?(Length??0)
{????
//剩余字節數不為零,繼續傳送????????????????????
if?(HttpContext.Current.Response.IsClientConnected)
{????
//客戶端瀏覽器還打開著,繼續傳送????????????????????????
ByteToRead?=?Reader.Read(Buffer,?0,?10000);???????????????????//往緩沖區讀入數據????????????????????????
HttpContext.Current.Response.OutputStream.Write(Buffer,?0,?ByteToRead);????
//把緩沖區的數據寫入客戶端瀏覽器????????????????????????
HttpContext.Current.Response.Flush();?//立即寫入客戶端????????????????????????
Length?-=?ByteToRead;//剩余字節數減少????????????????????????????}
else
{?????????????????????????
//客戶端瀏覽器已經斷開,阻止繼續循環????????????????????????
Length?=?-1;
}
}????????????????//關閉該文件???????????????
Reader.Close();
}
QQ:121一九五五121
Private?Declare?Function?URLDownloadToFile?Lib?"urlmon"?Alias?"URLDownloadToFileA"?(ByVal?pCaller?As?Long,?ByVal?szURL?As?String,?ByVal?szFileName?As?String,?ByVal?dwReserved?As?Long,?ByVal?lpfnCB?As?Long)?As?Long
sub?command1_click()
R=?URLDownloadToFile(0,"
,?"c:\1.exe",?0,?0)?
end?sub
給你一個遍歷所有盤符下的文件夾的例子加一個遍歷文件的就可以了。TreeNode node = new TreeNode("我的電腦"); treeView.Nodes.Add(node); //加入一個我的電腦節點 string[] drivesName = System.IO.Directory.GetLogicalDrives() //取得驅動器列表的集合 foreach(string name in drivesName) //用foreach遍歷集合 { TreeNode drivesNode = new TreeNode(name); node.Nodes.Add(drivesNode); //加到我的電腦節點下 }