Using http header to send file

Here's how you can make use of http header response to send a file direct to the clients browser for download.

 

    Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click

        Response.ContentType = "application/x-unknown"

        Response.AddHeader("Content-Disposition", "attachment; filename=test.txt")

        Response.WriteFile("test.txt")

        Response.End()

        Response.Clear()

 

    End Sub

Published Monday, May 26, 2008 6:48 AM by stoian bucovich

Comments

# re: Using http header to send file

Monday, May 26, 2008 10:35 AM by rajbk

You should clear the response stream first:

Response.Clear();

Raj

# re: Using http header to send file

Saturday, February 21, 2009 3:37 AM by stoian bucovich

Yes, you are right. Thank Raj

# Stoian bucovich | Alliterationpl

Saturday, November 26, 2011 3:50 PM by Stoian bucovich | Alliterationpl

Pingback from  Stoian bucovich | Alliterationpl

Leave a Comment

(required) 
(required) 
(optional)
(required)