views:

90

answers:

1

I have to create a tab delimited txt file from a query. I want to call an HttpHandler that returns my txt file as a stream, I don't want to create the file phisically.

1st question: what is the best practice to create the tab delimited txt file from a query result? I have to fetch all rows and create the file manually?

2nd question: How to set a timeout for the HttpHandler that creates the file?

Thanks for your time.

A: 
  1. I would create a plain old http output stream and change the content type to 'text/plain' which means that you don't need to physically create the file on the web server, and if you add the content-disposition header to the output and specify that it has an attachment called something like 'report.txt' the user will be prompted to Open or Save the content, rather than just viewing it in the browser like a normal web page.

  2. You can use the Server.ScriptTimeout = x to set the script timeout by gaining access to the current HttpContext object

Hope this helps

pb
Thanks for the answer. If I set the timeout like that, then it will override the scripttimeout for all pages of my application?
opaera
If you set the Server.ScriptTimeout for the current HttpContext then it will only affect the currently executing code.
pb
By currently executing code, I mean, the current page: All other pages in the site will run with the default ScriptTimeout value unless they themselves have a custom setting.
pb
Any chance of marking this as an answer?
pb