Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > export directly to excel file without prompting user

Reply
Thread Tools

export directly to excel file without prompting user

 
 
mattmerc@bellsouth.net
Guest
Posts: n/a
 
      02-27-2006
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(myHtmlTextW riter)

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

'End the response
Response.End()

 
Reply With Quote
 
 
 
 
Norman Yuan
Guest
Posts: n/a
 
      02-27-2006
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.


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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(myHtmlTextW riter)
>
> 'Write the HTML to the browser
> Response.Write(myTextWriter.ToString())
>
> 'End the response
> Response.End()
>



 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      02-28-2006
It seems you want to save the HTML to a file instead of writing it out to to
the response.
So instead of your second to last line you should have some code that writes
to the My.Computer.FileSystem namespace.
Here's more info:
http://msdn2.microsoft.com/en-us/library/0b485hf7.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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(myHtmlTextW riter)
>
> 'Write the HTML to the browser
> Response.Write(myTextWriter.ToString())
>
> 'End the response
> Response.End()
>



 
Reply With Quote
 
mattmerc@bellsouth.net
Guest
Posts: n/a
 
      02-28-2006
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.
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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(myHtmlTextW riter)
> >
> > 'Write the HTML to the browser
> > Response.Write(myTextWriter.ToString())
> >
> > 'End the response
> > Response.End()
> >


 
Reply With Quote
 
Shunya
Guest
Posts: n/a
 
      02-28-2006
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

 
Reply With Quote
 
mattmerc@bellsouth.net
Guest
Posts: n/a
 
      02-28-2006
Does Excel need to be installed on the server for this to work? Thanks.
Shunya wrote:
> 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


 
Reply With Quote
 
mattmerc@bellsouth.net
Guest
Posts: n/a
 
      02-28-2006
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!

 
Reply With Quote
 
Shunya
Guest
Posts: n/a
 
      03-01-2006
Ya For this, Excel has to be installed on the server

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to Excel (Default File Type - Excel) =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?= ASP .Net 15 05-21-2009 12:01 PM
Print directly in IE without prompting user Billy Zhang ASP .Net 2 08-06-2008 03:26 AM
Prompting user to save a Javascript created text to a file Jeff Javascript 4 01-17-2007 07:49 PM
Restrict user to directly call an excel file by typing URL in browser address jonesy Java 0 10-26-2006 07:03 AM
open vbs file without prompting File Download message =?Utf-8?B?a2lt?= ASP .Net 3 12-15-2005 02:13 AM



Advertisments