473,394 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

export directly to excel file without prompting user

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()

Feb 27 '06 #1
7 4891
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.
<ma******@bellsouth.net> wrote in message
news:11**********************@e56g2000cwe.googlegr 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()

Feb 27 '06 #2
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

<ma******@bellsouth.net> wrote in message
news:11**********************@e56g2000cwe.googlegr 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()

Feb 28 '06 #3
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.
<ma******@bellsouth.net> wrote in message
news:11**********************@e56g2000cwe.googlegr 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()


Feb 28 '06 #4
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

Feb 28 '06 #5
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


Feb 28 '06 #6
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!

Feb 28 '06 #7
Ya For this, Excel has to be installed on the server

Mar 1 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Zero | last post by:
how to Overwrite Existing Excel File without prompt and quit?
3
by: kim | last post by:
GOOD morning, I try to open xx.vbs in <href="./xx.vbs"></hef> but it pop up the file download mesage. How can i disabled it? I try another solution like this : set ws =...
3
by: Miguel Ramirez | last post by:
Hello all, Is there any way to import an excel file data from user's computer? I want to read all records in the excel file and write the data in a SQL server table. Any help will be really...
7
by: alwayssmiling | last post by:
Hi frends, In my application, a class supports backend processing. In this class im creating a new excel sheet and im inserting some data into this excel sheet, and im trying to save the file...
2
by: solargovind | last post by:
Hi, Can anybody suggest me how to take data from an Excel file without import into Access as a Table..? Bcoz...I hve several file. if i import, it would take more time and increase the file...
2
by: radraq | last post by:
Hello, I have just completed a survey in excel which I've uploaded to my website. The propblem is I would like the excel file to open directly online without asking for paswords and save the...
16
AnuSumesh
by: AnuSumesh | last post by:
Hi, I am ridirecting page to vbs file. File is running properly but it is asking user to open/save the file. But i want that it should run without any dialouge box. My code is : ...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net page, it uses js to print in IE. It always has the prompting user window appear. I have tried: <input onclick="document.all.WebBrowser.ExecWB(6,6)" type="button"...
0
by: Ivan Stefanov | last post by:
Hello, I have the following problem: I created a website project and I want in that website to be make a button, which will export some data in an excel file. This is the code that I have: using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.