Problem downloading csv file

G

Guest

Hi All,

I have an asp.net 1.1 application that includes a rudimentary contacts database that must support importing from and exporting to Outlook. The file upload part works fine, but I'm having trouble allowing users to download their contacts so that they can import into Outlook.

I am using a csv file to exchange the data been our system and Outlook. For security reasons I have avoided writing user's contacts to a csv file on the server and then providing a link to it, and have instead tried to create the required output and stream it directly to their browser.

The code that creates the csv file is contained in a class that implements the IHttpHandler interface. It sets the following headers:
Context.Response.ContentType = "text/comma-separated-values"
Context.Response.AppendHeader("Content-Disposition", "attachment; filename=""Contacts.csv""")

It also queries the database and loops through the records using response.write statements to create the required output.

The application's web.config file has the appropriate <httpHandlers> element, and the application has been configured to handle .csv files with the aspnet_isapi.dll ISAPI extension.

This setup works exactly the way I want it to on the development server: The application redirects the user to a file called Contacts.csv and they are prompted to save the file to their hard drive with the name Contacts.csv. The file is then downloaded successfully.

On our production server the user is prompted to save the file. However after clicking the save button the users receive the following error:

Internet Explorer cannot download Contacts.csv from ServerName.

Internet Explorer was not able to open this Internet Site. The requested site is either unavailable or cannot be found. Please try again later.

Any ideas about what could be causing the error?

Regards,

Guy Penfold
 
P

Patrice

Do you have something in the IIS log for this request ?

Does it work when streaming directly from an ASPX page ?

Guy Penfold said:
Hi All,

I have an asp.net 1.1 application that includes a rudimentary contacts
database that must support importing from and exporting to Outlook. The file
upload part works fine, but I'm having trouble allowing users to download
their contacts so that they can import into Outlook.
I am using a csv file to exchange the data been our system and Outlook.
For security reasons I have avoided writing user's contacts to a csv file on
the server and then providing a link to it, and have instead tried to create
the required output and stream it directly to their browser.
The code that creates the csv file is contained in a class that implements
the IHttpHandler interface. It sets the following headers:
Context.Response.ContentType = "text/comma-separated-values"
Context.Response.AppendHeader("Content-Disposition", "attachment; filename=""Contacts.csv""")

It also queries the database and loops through the records using
response.write statements to create the required output.
The application's web.config file has the appropriate <httpHandlers>
element, and the application has been configured to handle .csv files with
the aspnet_isapi.dll ISAPI extension.
This setup works exactly the way I want it to on the development server:
The application redirects the user to a file called Contacts.csv and they
are prompted to save the file to their hard drive with the name
Contacts.csv. The file is then downloaded successfully.
Internet Explorer cannot download Contacts.csv from ServerName.

Internet Explorer was not able to open this Internet Site. The requested
site is either unavailable or cannot be found. Please try again later.
 
G

Guest

Thanks for your response,

The log file indicates that the requests are being handled ok. The server returns a 200 code and the size of the response is as expected

It doesn't work when streaming directly from an .aspx page either. This was the original approach that I took and I only switched to using an http handler when I ran into problems

Guy
 
P

Patrice

Could it be an execution error during the request ?

I never ran into such a problem when streaming files. You could comment the
header to just display the file. It would allow to check if the whole
content is streamed or if it's cut before the expected end...

The only difference I see is that I'm calling Response.Clear to make sure
the buffer is cleared and I'm not using " to enclose the filename.

Patrice


Guy Penfold said:
Thanks for your response,

The log file indicates that the requests are being handled ok. The server
returns a 200 code and the size of the response is as expected.
It doesn't work when streaming directly from an .aspx page either. This
was the original approach that I took and I only switched to using an http
handler when I ran into problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top