Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically serving a file to a user

Status
Not open for further replies.

yumbelie

Programmer
Dec 31, 2002
96
GB
Hi,
Basically, what I am trying to do is automatically serve a file to a user, so that when the html page reloads, the user is prompted to "save/open the file". However, the file to be served is created by an external DLL, which then writes it to a folder where the ASP website is stored, e.g.:

1) Website in x:\inetpub\ ASP script 'write_file.asp' calls vb dll
3) VB DLL creates file, and writes to x:\inetpub\4) ASP script continues executing, and proceeds to write the following Response headers:


Response.AddHeader "Content-Disposition", "attachment; filename=" & Chr(34) & strFileLocation & Chr(34)
Response.AddHeader "Content-Length", objRM.strFileLength
Response.ContentType = "text/csv"


which serve the file.
5) Some HTML is written to the browser, indicating success in a particually garish neon text.

* objRM is a class of the DLL, that writes out the file
* strFileLocation is supposed to be where the file is stored, I've tried absolute values with Server.MapPath("tmpfiles\") & "report.csv", as well as relative values, like: "/tmpfiles/report.csv" and "\tmpfiles\report.csv" and other attempts with and without the first slash.

Now, IE prompts with a file save box, but proceeds to serve the HTML that is output from the write_file.asp script after the response.addheaders are called. I cannot get it to serve the report.csv that has been generated. I'm not sure if it's a security issue (I've added a virutal directory in the IIS Services Control) or, if I'm just pathing incorrectly.

If anyone could provide exact details on how exactly I'm supposed to accomplish (Headers, security settings etc) this task, I'd be most grateful as I'm pretty new to ASP, and it's a bit different to PHP ;)

Many Thanks

Yum.
 
i dont believe you can mix a response.header output ( a file stream ) and html, because then you're forcing the browser to try and choose is it a file that's trying to download or is it a web page...

you could fool the output say ...

<body onload="window.open('csvoutput.asp?myargs=blah');">

OR in the page somewhere have :

<script>
window.open('csvoutput.asp?myargs=blah');
</script>

then the page will prompt to open the csv, and still have all your html in there
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top