# Thread: Can you 'reset' Response.ContentType ??

1. ## Can you 'reset' Response.ContentType ??

My client wants to extract records by country from an Excel spreadsheet.
So I have one script which reloads itself twice :-
phase 1. display initial form, user select s country and Submits
form action reloads itself with querystring '...?Extract=YES'

phase 2. Extract=YES
the extract code contains the following
Response.Buffer = true
Response.ContentType = "application/vnd.ms-excel"
...
...
Response.Flush
and stores a record count/message in session variables
now somehow reload script with querystring '...?Extract=DONE'

phase 3. Extract=DONE
display record count/message in session variables using Response.write

The actual extract works fine, creates the Excel file, but then stops/hangs ??
It doesn't reload and perform phase 3.

From 100s tests and various answers via Google, I've gathered that it's the RESPONSE method that I'm not understanding or using correctly. I've tried :
Response.Redirect ("scriptname?Extract=DONE")
Server.Transfer doesn't accept the ?Extract=DONE
even a javascript window.location.replace("scriptname?Extract=DONE") and
window.location.href = "scriptname?Extract=DONE"
but nothing happens

Is there a way to 'reset' the Response.ContentType and Headers?, so I can Response.write my record count/message ??

Can anyone dig me out of this hole ??

2. If you've got the content type set to something other than html, I don't think you can use the redirects (but it's been a while since I've done anything like that).

What I've always done is just create the file on the server, then provided a link to the generated file. The benefit here is you're always sure what has been provided to the user AND the file can be reaccessed at a later date if needed. A csv file will work just as well as an excel spreadsheet unless he wants it formatted or something.

Code:
Set objFS = CreateObject("Scripting.FileSystemObject")
fileName = "excel\text.csv"
If objFS.FileExists(fileName) Then  ' Check is here just to ensure the file was created....
Set objFile = objFS.OpenTextFile(fileName, 8) ' 8 is for append
Else
Set objFile = objFS.CreateTextFile(fileName, True)
End If

For i = 0 to 100
objFile.Write ("1,2,3,4,5,6,7,8" & CHR(13) & CHR(10))
Next
objFile.Close

Response.Write "The generated file is <a href=""excel/text.csv"">here</a>"

3. Thanks Dave, I've got this working now based on your example with FSO.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•