簡體   English   中英

允許用戶下載文件

[英]Enabling a user to download a file

我正在圖像庫上工作,在瀏覽圖像模塊上,我有一個下載圖標。 我需要它作為下載按鈕。 當用戶點擊它時,它們應顯示保存文件對話框,或者應使用其默認瀏覽器下載設置下載文件。

我嘗試了很多方法,但沒有運氣。

  • 下載圖標顯示在Modal-popup中,因此所有代碼都包含在UpdatePannel中

  • 這些圖像的格式不同(jpeg,gif,tif,psd)

最后整理出來:

A)在客戶位置下載文件:

public void downloadFile(string fileName, string filePath)
    {
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", fileName));
        Response.WriteFile(filePath + fileName);
    }

B)由於函數觸發控件( imgDownloadimgDownloadPsd )被包裝在異步調用下:將其添加到頁面加載:

protected void Page_Load(object sender, EventArgs e)
{   ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(imgDownload);
    ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(imgDownloadPsd);
}  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM