export directly to excel file without prompting user

M

mattmerc

Hi all,

We have all seen lot of method for exporting datagrids to Excel. I have
a slightly different need. I think it should be easy to accomplish but
I am not sure how. I would like when a user clicks a button for
exporting a datagrid, that the excel file is saved on the server and
that it DOES NOT prompt the user to open or save. Here is the code I am
using for standard export that prompts the user. Thanks all.

Dim dgrd_export_daily_report As New Datagrid 'Create new Datagrid
without link and paging
dgrd_export_daily_report.Datasource = dst_export_daily_report
dgrd_export_daily_report.Databind()
'Tell browser to format output for Excel not IE
Response.AddHeader( "Content-Disposition", "attachment; filename=" &
str_file_name & "")
' Set the content type to Excel
Response.ContentType = str_application

'Turn off the view state
Me.EnableViewState = False

'Remove the charset from the Content-Type header
Response.Charset = String.Empty

Dim myTextWriter As New System.IO.StringWriter()
Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter)

'Get the HTML for the control
dgrd_export_daily_report.RenderControl(myHtmlTextWriter)

'Write the HTML to the browser
Response.Write(myTextWriter.ToString())

'End the response
Response.End()
 
N

Norman Yuan

Where do you exactly want to save the Excel file? On ther server, as you
mentioned in the beginning of your post, or on user computer, as your code
shows?

Since your code is to send data to client, of course you get prompt for
saving/openning. Data from web server is not allowed to silently save data
to user's computer, for safety reason.

You need entirely different code to save the data on the server, if that is
what you want.
 
M

mattmerc

Yes, as you stated, what I need is exactly what I said I needed. :) My
sarcasm isn't going to get me any help so I should probably
stop...sorry.

I gave the code example to show what I have used to export to a client
in hopes that it only needed to be modified so I could save on the
server. Based on your response, I guess that isn't true.
 
S

Shunya

HI,
There is a solution to your problem. You can use interop.excel and
create excel through console application. And then the exe created by
that application can be called by remoting through asp application.
Thus we can avoid the prompt and can create multiple excel files
 
M

mattmerc

Thanks all for the help so far. I have done a lot of reading, and I
think I need to repost my question because it looks like the need is
slightly different now than i had originally anticiapted. We all know
how that goes... Thanks again!
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top