Re: export directly to excel file without prompting user



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.


Norman Yuan wrote:
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.


<mattmerc@xxxxxxxxxxxxx> wrote in message
news:1141065639.217774.148970@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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()


.


Loading