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

1.9k Views Asked by At

i am trying to open the downloaded file from database in a new browser window..

here is code that i tried..

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();
            }

is there any syntax to open in jquery?

1

There are 1 best solutions below

3
On

The code you provided isn't jQuery, it's C#. This question actually has nothing to do with jQuery, so please be mindful not to add irrelevant tags to your question next time :).

To open a (downloaded) file in the browser, set the Content-Disposition header for your Response object to inline. Currently, you are setting it to attachment which forces it to be downloaded as a file instead of being displayed in the browser.

Example:

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