0
votes

I am having problem with Response.ContentType Conflicts with Progress Bar. Basically, I am trying to display a pop up progress bar while saving the recordset to a CSV file.

I use this two lines below everywhere to call the progress bar and close it at the bottom of a page, so it works with regular page without (Response.AddHeader "Content-Disposition", "attachment;filename=export.csv")

response.write("<script language=""javascript"">ProgressStart();</script>")
Response.Write("<script>ProgressDestroy()</script>")

I am getting this error below, and I know it is conflicting with the Response.ContactType "text/csv".

    Response object error 'ASP 0156 : 80004005'

Header Error

/Apps/ERP/Company/ExportCompanyView.asp, line 253

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content. 

Is there a way to by pass or trick it, so I won't conflict with "Response.ContentType = "text/csv""?

Thanks in advance,

This code is where all the process happens:

If SOViewSQL <> "" Then
    set rs1 = conn.execute(SOViewSQL)

    response.write("<script language=""javascript"">ProgressStart();</script>")
    response.flush()    

    Write_CSV_From_Recordset RS1
    Response.ContentType = "text/csv"
    Response.AddHeader "Content-Disposition", "attachment;filename=export.csv"

    Response.Write("<script>ProgressDestroy()</script>")
    'response.flush()


    set rs1 = nothing
    conn.close
    set conn = nothing

End If
1
You Response can be either a CSV file or HTML, but not both. - Tim Williams

1 Answers

0
votes

You'll have to rewrite your page script so all processing is done before anything (headers or page content) is sent to the client, and then make sure you send all headers before you call Response.Write or use %>.

Like so:

Dim showProgressScripts
showProgressScripts = False

If SOViewSQL <> "" Then

    Set rs1 = conn.Execute(SOViewSQL)

    Write_CSV_From_Recordset RS1
    Response.ContentType = "text/csv"
    Response.AddHeader "Content-Disposition", "attachment;filename=export.csv"


    Set rs1 = Nothing
    conn.close
    Set conn = Nothing

    showProgressScripts = True

End If %>

<p>my page content here</p>

<% If showProgressScripts %>
<script>ProgressStart();</script>
<script>ProgressDestroy();</script>
<% End If %>

Of course, your script looks like you're serving HTML as a CSV file - I think you need to reconsider what you're doing.