0

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?

thiru
  • 173
  • 1
  • 4
  • 16
  • 1
    The `Content-Disposition` key you are adding is a suggestion to download the file. Remove the header and open the link in a blank tab – Icepickle Feb 22 '16 at 17:36
  • Possible duplicate of [How to open PDF file in a new tab or window instead of downloading it (using asp.net)?](http://stackoverflow.com/questions/8294057/how-to-open-pdf-file-in-a-new-tab-or-window-instead-of-downloading-it-using-asp) – Liam Feb 22 '16 at 17:37
  • @Liam i couldn't found my answer in that link... – thiru Feb 22 '16 at 17:54

1 Answers1

1

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));
nbokmans
  • 5,492
  • 4
  • 35
  • 59
  • I think the jquery tag is because the Op would accept a jquery solution, that said why jquery and not javascript.. – Liam Feb 22 '16 at 17:38
  • The code that he posted which he tried was C#, which is why I assumed he wanted a C# solution. – nbokmans Feb 22 '16 at 17:39
  • The code you posted leads me to believe this is a result from a `Controller` action. You don't have access to jQuery there. – nbokmans Feb 22 '16 at 17:45