簡體   English   中英

如何在新的瀏覽器窗口中打開下載的文件C#

[英]How to open the downloaded file in new browser window c#

我正在嘗試在新的瀏覽器窗口中打開從數據庫下載的文件。

這是我嘗試過的代碼。

result = objBL.GetLetter(LetterID, refNo, attachmentType);
            if (result != null && result.Rows.Count > 0)
            {
                DataRow dr = result.Rows[0];
                string fileName = dr["FileName"].ToString();
                Response.ContentType = ContentType;
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(fileName));
                Response.WriteFile(Server.MapPath("~/Attachments/" + fileName));
                Response.End();
            }

有什么語法可以在jquery中打開嗎?

您提供的代碼不是jQuery,而是C#。 這個問題實際上與jQuery無關,因此請注意下次不要在問題中添加無關標簽:)。

要在瀏覽器中打開(下載的)文件,請將Response對象的Content-Disposition標頭設置為inline 當前,您將其設置為attachment ,這將強制將其下載為文件而不是顯示在瀏覽器中。

例:

Response.AppendHeader("Content-Disposition", "inline; filename=" + Path.GetFileName(fileName));

暫無
暫無

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

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