
復制代碼 代碼如下:
private void BtnOpen_Click(object sender, System.EventArgs e)
{
if(FileList.SelectedItem.Text=="返回上級目錄") //返回上級目錄
{
string ParentPath=Directory.GetParent(CurrentPath).ToString();
LoadDir(ParentPath);
return;
}
else if(FileList.SelectedItem.Text.IndexOf(".")>0) //打開文件
{
FileDownload(FileList.SelectedItem.Text);
}
else //打開目錄
{
LoadDir(FileList.SelectedItem.Text);
}
}
復制代碼 代碼如下:
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(YourFileName); //設置要下載的文件
Response.Clear(); //清除緩沖區流中的所有內容輸出
Response.ClearHeaders(); //清除緩沖區流中的所有頭
Response.Buffer = false; //設置緩沖輸出為false
//設置輸出流的 HTTP MIME 類型為application/octet-stream
Response.ContentType = "application/octet-stream";
//將 HTTP 頭添加到輸出流
Response.AppendHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
//將指定的文件直接寫入 HTTP 內容輸出流。
Response.WriteFile(DownloadFile.FullName);
Response.Flush(); //向客戶端發送當前所有緩沖的輸出
Response.End(); //將當前所有緩沖的輸出發送到客戶端
}
新聞熱點
疑難解答
圖片精選