force download for files using webBrowser control

E

E Stafford

I am creating a form app that uses a webBrowser control and allows users
to interact with a web hosted application. Users can query the web
app and generate a CSV file that they should be able to save locally.

When the button to save the csv is hit on the page displayed in the
webBrowser control, the CSV file generated by the app opened in a new
webBrowser control and rendered as plain text with comma seperated format.

How can I force the csv file to be dowloaded instead of rendered in a
new window?

Thank You for your help.
 
N

Nicholas Paldino [.NET/C# MVP]

E,

You can do this by adding a header in the response for the content
disposition. Check out the knowledge base article titled "How To Raise a
"File Download" Dialog Box for a Known MIME Type" located at (watch for line
wrap):

http://support.microsoft.com/default.aspx?scid=kb;en-us;260519

The code is for the old ASP (it's only one line), but you can easily use
this in .NET (as a matter of fact, I used this for a file download site that
we use here internally).

Hope this helps.
 
E

E Stafford

Thanks Nicholas,
If I understand right, the example you provided required me to be able
to modify an asp page by adding a response header to the page. I do not
have the ability to do that in this situation. The web application being
accessed through the webbrowser control hosted in my windows form
application is provided by a 3rd party service that our company uses. I
do not have the ability to modify the pages. I have seen articles that
hinted at the idea of rewriting html source but I am not familiar with
the technique. Is there a way to modify the headers before they are read
by the browser control? Would that be an option or can I not alter the
response headers after the browser control recieves it?
 

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

Top