Kyle J V
Kyle J V

Reputation: 603

How can I send a download of a file from a modal window?

Currently, this code works fine in a regular browser window:

    if (readerObj.Read())
    {
        filename = readerObj["TRANATTACHMENTNAME"].ToString();
        fileBytes = (byte[])readerObj["TRANATTACHMENT"];

        Response.Clear();
        Response.ContentType="application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
        Response.BinaryWrite(fileBytes);
        Response.Flush();
        Response.End();

        dbConnectorObj.Connection.Close();
        dbConnectorObj = null;

        return true;

    }

Unfortunately, this window needs to be modal (i'm modifying an already existing application). When I run the window modally, there's no file download dialogue.

ASP.NET 2.0

Any thoughts?

Upvotes: 1

Views: 453

Answers (1)

Dustin Laine
Dustin Laine

Reputation: 38503

I would change the way you are doing this and have the file be server via an HTTP handler. Then you can just link the the handle url passing in the pertinent data to pull correct file or perform authentication and the dialog will pop up regardless.

Upvotes: 1

Related Questions