Question Response.addheader not working with .net Framework 4

gwaddell

New member
Joined
Jan 13, 2010
Messages
4
Programming Experience
10+
Hi

I'm writing a site that allows users to download documents securely stored on the network off of the web server.

I'm using a com object on the server that we've been using here for ages that fetches the file from the network in a binary stream thus preventing user access to the network.

The problem I'm having is when the user clicks on the link, instead of the file opening, the page reloads itself with the stream as its source.

On the open save dialog instead of filename.* I get MyPage.aspx as the file name it is as if my response.AddHeader is not working.

It all works fine on my localbox -it only happens after I publish to a test deployment server.

(This is the first time I've tried this in Visual studio 2010 with .Net framework 4.)
Here is my Page and code:
HTML:
<!-- Inside a Repeater Item.... -->
<asp:LinkButton ID="MyLink" runat="server" CommandArgument='<%# Eval("FilePath") %>' CommandName='<%# Eval("FileName") %>' ToolTip="Open File" OnCommand="LinkButton1_Click" CssClass="PrimaryNavigation"><%# Eval("FileName") %></asp:LinkButton>

<!--End of Repeater Item -->
And here is my code behind:
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs) 
        Dim o As Object = CreateObject("#######") 'object that brings back stream
        Dim vntStream() As Byte
        Dim CmdArg, CmdName As String
        CmdArg = e.CommandArgument 'fullpath to file 
        CmdName = e.CommandName 'Filename
       'get binary stream
        vntStream = o.FetchDocument(Server.UrlDecode(CmdArg.ToString)) 
       
        'Add header - does not seam to be working
        Response.AddHeader("Content-Disposition", "Attachment; Filename=" & CmdName)

        'Write Out Binary stream
        Response.BinaryWrite(vntStream)

        'Finish
        Response.End()

    End Sub

Like I said, it looks like the line Response.AddHeader("Content-Disposition", "Attachment; Filename=" & CmdName) is not working as I get the name of my page in the file dialog.

Anyone out there see what's going wrong?
 
Back
Top