views:

11

answers:

1

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?

+1  A: 

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.

Dustin Laine
Thanks. Following your advice, I created the file and used ClientScript.RegisterStartupScript(this.GetType(), "scrDownloadFile", @"window.open('TempFiles/" + filename + "')", true);instead of the response object.
Kyle J V