开发者

ASP Force Download

开发者 https://www.devze.com 2023-02-12 03:15 出处:网络
In PHP I can do: header(\"Content-type: application/octet-stream\") and then anything that I output is downloaded instead of showing in the browser.

In PHP I can do: header("Content-type: application/octet-stream") and then anything that I output is downloaded instead of showing in the browser.

Is there a similar way to do this in ASP? I have seen about all the file streaming and such using ADODB.Stream, but that doesn't seem to work for me and always requires another file to load the content from.

Bit of an ASP noob, so go easy on me. :p All I want to do is have a script that outputs a CSV and that will force download instead of showing in the browser.

Thanks

EDIT

here is my script currently:

reportingForce.aspx.vb

Public Class reportingForce
  Inherits System.Web.UI.Page

  Dim FStream

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Response.Buffer = True
    Response.ContentType = "applicati开发者_如何学Con/octet-stream"
    Response.AddHeader("Content-disposition", "attachment; filename=" & Chr(34) & "my output file.csv" & Chr(34))
    Response.Write("1,2,3,4,5" & vbCrLf)
    Response.Write("5,6,7,8,9" & vbCrLf)
  End Sub

End Class

reportingForce.aspx

Hello,World


You can use:

Response.ContentType = "application/octet-stream"


I'd do both..

Response.Buffer = True
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-disposition", "attachment; filename=" & Chr(34) & "my output file.csv" & Chr(34)
Response.Write "1,2,3,4,5" & vbCRLF
Response.Write "5,6,7,8,9" & vbCRLF


The correct way to do this is to change the "Content-disposition" response header to "attachment". You don't need to change the content type.

I believe you can do something like this in ASP:

Response.AddHeader "content-disposition","attachment; filename=whatever.csv"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号