AJAX :: Allowing Clients To Download Excel Spreadsheet Using Response.Write?

Jun 24, 2010

I've a gridview which I am rendering to a html text writer and allowing clients to download as an excel spreadsheet using Response.Write. I'm using AJAX in my website now and suddenly it stopped working. This is the code I'm using

public static void Convert(DataSet ds, HttpResponse response)
{
try
{
//1. declare filename to export
string filename = "export";
//2. clear response object
response.Clear();
response.Charset = "";
//3. set response mime type to excel
response.ContentType = "application/vnd.ms-excel";
//4. prompt user to download the file
response.AppendHeader("content-disposition", "attachment; filename=" + filename + ".xls");
//5. create a string writer
StringWriter stringWrite = new StringWriter();
//6. create html writer which uses the string writer
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//7. instantiate a gridview
GridView gv = new GridView();
//8. set gridview datasource to the dataset
gv.DataSource = ds.Tables[0];
//9. bind gridview
gv.DataBind();
//10. tell the gridview to render itself into htmltextwriter
gv.RenderControl(htmlWrite);
//11. output html
response.Write(stringWrite.ToString());
//12. end response
response.End();
}
catch (Exception ex)
{
string str = ex.Message;
}
}

I've found that Response.Write doesn't work with AJAX. Are there any alternatives to this?

View 3 Replies


Similar Messages:

AJAX :: ModalPopupExtender Won't Hide After Response.Write With Excel

Aug 18, 2010

I am having a great deal of difficulty getting a ModalPopupExtender to hide after I export a datatable to Excel.

If I simply rem out the Response.write in the code below, everything works correctly, but of course I don't get my excel sheet.

I have tried all kinds of ways to do this. Including calling a javascript function to hide it, wrapping the Panel in an updatePanel and placing the TransactionControl in a asp:PostBackTrigger.

All without affect. Anyone have a clue as to how to do this?

I was also hoping some event would fire after the ModalPopupExtender hides, but of course there is no such luck.

[Code]....

View 1 Replies

Architecture :: Write A Response To Let Users Download A Big File From DB?

Mar 11, 2010

I am a newbie of handling memory.

in my web apps, files are stored as varbinary in sql server.

my goal is to make a response to let users to download the files.

if there is a file (500 MB) stored in one record in the sql server,

what is the best way to let users download it?

I found that , in code-behind, if the files are loaded as byte[] objects, it uses the memory.

for example, the datalength of a file in the database is 500 MB.

the byte[] for this file uses 500 MB memory. am I correct?

how about the filestream? if the file is loaded as a filestream object in code-behind.s

does it also take 500 MB memory?

View 2 Replies

C# - HttpContext.Current.Response Write File After Download Manager Starts?

Dec 17, 2010

I'm trying to create a ZIP file on the fly which might contain a few thousands of pictures.

[code]....

My question:

Is there a way to initiate the download (let the download manager on client side popup), and then start writing on the stream?

I monitored w3wp.exe (IIS) process, and it seems that the data is being written on memory instead of Stream.

When w3wp.exe memory usage riches a certain number, it releases the memory and nothing happens (no download).

View 2 Replies

Web Forms :: Load File From Database And Write A Response To Let User Download?

Mar 10, 2010

I am a newbie of asp.net.

The environment is .net 3.5 and C#.

There are files stored in sql server (datatype of column is varbinary in the database).

each record is in one record in that table (FILE_TABLE).

And there is another table (PATH_TABLE) to store the files paths.

for example,

when the user download the folder A (select an item on the tree and click a button on the client side),

there is one sub-folder B and two files A-1 and A-2.

in folder B, there is two files B-1 and B-2.

then, at the code behind (server), the server will get the files from the database and convert them (including the files and subfolders) to a .zip file (or other compressed files)

and then write a response (using the method HttpResponse.BinaryWrite(Byte[] xxx) )

to client side and let the user download.

after the download, the user can extract the compressed file and the structure of the folders and files keep unchanged.

View 4 Replies

C# - Generate File For Download Using Response.Write And Change Elements On The Webpage?

Aug 25, 2010

I am trying to change the text of a asp:textbox and collapse some ajaxToolkit:CollapsiblePanelExtenders within some ascx controls on my page as well as output a dynamically generated file. I have no problem collapsing the CollapsiblePanelExtenders and changing the text of the textbox from the codebehind or outputting a file. The problem arises when I want BOTH of these events to happen on the same postback. Unfortunately using Response.Write negates all of the other changes to the page.

View 1 Replies

AJAX :: Rating_Changed Event Not Allowing Response.redirect To Navigate?

Apr 10, 2010

I'm using one Rating control and only logged in users can able to rate the article. Below is the code I'm trying

<ajaxToolkit:Rating ID="PostRating" runat="server" BehaviorID="RatingBehavior1" StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar"
OnChanged="PostRating_Changed" Style="float: left;" CurrentRating="0" />

[Codee]....

This throws an error at Response.Redirect. Error message is "Response.Redirect cannot be called in a Page callback".

View 1 Replies

Web Forms :: To Use Response.Write To Adjust Column Widths When Exporting Data To MS Excel?

Feb 14, 2010

Is there a simple way to use Response.Write to adjust column widths when exporting data to MS Excel?

View 3 Replies

Automatic Download Of A Web Resource From A Spreadsheet?

Jan 11, 2011

I have a datasource of an excel spreadsheet provided by a customer. The data is biographic information about clients. The last row contains a web link to view an image of the subject. I have open access to download the spreadsheet and can click each image to view the full jpg in IE.

What would be the best method to loop through the image link to deposit the image into a central file location? The datasource contains 50K subjects and is updated monthly, this is why a manual process is out of the question.

View 1 Replies

What's Difference Between Response.write And Response.output.write

Apr 22, 2010

what is difference between Response.write and Response.output.write

View 2 Replies

AJAX :: CollapsiblePanelExtender Not Working With Response.write?

Feb 28, 2011

i am using CollapsiblePanelExtender and button to open pdf document using response.document in same form. CollapsiblePanelExtender works fine before i click button to open pdf document using response.write and once i click on button CollapsiblePanelExtender does not work.

View 2 Replies

AJAX :: Can Use Response.write In Conjunction With An UpdatePanel

Feb 11, 2010

I want to bring up an Alert messagebox if a user does not fill in a field on my webform before clicking a submit button on the form. I also want to use an UpdatePanel because it makes it a smoother user experience. But I am experiencing a conflict with

response.write("<script>alert('fill in Comment before submitting');</script>");

and the UpdatePanel. If I remove the Updatepanel then I can use my Alert message above but it loses the page temporarily until the user clicks "OK" on the messagebox. My alternative - using the UpdatePanel - was to add a label to the webform where if a user does not fill in the requested info - a label would display text giving the same message - very smoothly with the UpdatePanel. But the label is not modal like the Alert message.

Is there a way I can use response.write in conjunction with an UpdatePanel? The webform is fairly basic. It has a couple of asp.net textboxes and labels and an asp.net button control. I guess I could use a "required" label, but I like the modal property of the Alert message better.

View 4 Replies

Generate Excel Spreadsheet From CSV?

Nov 15, 2010

Possible Duplicate: Create Excel (.XLS and .XLSX) file from C#

I have some code that generates a zip file that contains multiple CSV files and streams it back to the user (no file is saved on the server). However, I want to create an excel workbook instead (can be traditional xls or Office Open XML xlsx format) with each CSV 'file' being a spreadsheet.

How can I do this, without resorting to Office Automation on the server or a commercial 3rd party component?

View 4 Replies

AJAX :: Response.write Not Working Inside UpdatePanel?

Feb 23, 2010

I have populated my data using DataRepeater Control and i have a Delete button on that so each and every row has a delete button which allows user to delete a single entry from DB. I have put this control inside UpdatePanel so i can avoid full page postback.

When i delete the row from the database and try to show a alert message using Repsonse.Write it throws me the below error message

Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near 'itle||Untitled Page|<script language='ja'. Source File: [URL]

But, If i remove my update panel its coming up well, is there any solution so i can show alert box after a row been deleted ?

View 8 Replies

Display Graph From Excel Spreadsheet?

Jun 10, 2010

I'm working on a project which requires me to plot a graph using Visual Studio ASP.Net from a data I've collected either in .txt or .xml format. The data consist of, eg. 15 records, but I'm only needed to plot 8 graphs out of the 15 records.

View 1 Replies

How To Freeze The Header Row In An Excel Spreadsheet

Feb 25, 2010

I'm exporting an ASP.NET gridview to Excel using the following function. The formatting is working really well, except I need to freeze the header row in Excel on the export. I'm really trying to avoid using a 3rd party Excel plugin for this, but unless there's some archaic excel markup in my AddExcelStyling function.

[code]....

View 2 Replies

Two Dimensional Array To Excel Spreadsheet

Jun 22, 2010

I have a 2 dimensional array, I want to convert it to an Excel document using C#.

View 2 Replies

SQL Server :: FileUpload Excel Spreadsheet?

Aug 13, 2010

I'm trying to upload an excel spreadsheet using the FileUpload control, read the excel sheet using OleDb connection, and save the strings onto a sql server database.Then, I'm trying to read each string in another method.My web app is currently hosted on the network on my local box, and using savePath= @"C:desktop" like I had it previously wasn't working, so I figured using a sql server database would work for being able to save the file and open it again... but I'm getting confused on how to do so, so i tried using my old savePath but it's not working anymore. So... I'm really at a lost on what to do and how to fix it.

[Code]....

View 1 Replies

Create Excel Spreadsheet In Website

Nov 14, 2011

On an .aspx page in a web site I need to retrieve some data from a sql server database and, instead of displaying it in a Gridview, I need to put the data in a spreadsheet and present the user with a Save As dialog.

I'd prefer to do it without using the Office / Excel / Interop com object - so, from what I've read so far, I can do this by returning XML data from SQL Server?

Normally I get data from SQL Server and populate a dataset or datareader with it - and then use this as the Datasource of a GridView.

If I run this in SQL Server ...

Code:
SELECT UserID, UserName FROM tblUsers FOR XML Auto, Root('Users')

It produces this ...

Code:
<Users>
<tblUsers UserID="1" UserName="Steve" />
<tblUsers UserID="2" UserName="Andrea" />
<tblUsers UserID="3" UserName="Zebedee" />
</Users>

So, first question - how do I get the data from SQL Server into my .aspx page? (All data access is done with stored procedures - so, from my data access class normally I create, for example, a SQLDataReader and populate it by calling a stored procedure. What object would I populate with the results of a stored procedure that contains a select statement with 'FOR XML Auto'

Then, assuming I get the XML into the .aspx page - how do I get it into a spreadsheet so that there are two columns called UserID and UserName and 3 rows with 1, 2 and 3 in the first cell and Steve, Andrea and Zebedee in teh second cell?

View 9 Replies

Globalize/Localize Excel Reports Using Spreadsheet?

May 28, 2010

My company has new customers in Brazil and we realized that our excel reports are not working when our Brazilian customers tried to open the reports in their Brazilian versions of excel.

For excel output we use spreadsheet gear in our vb.net web application. Our excel worksheets are fairly simple. Mostly outputted text/numbers/dates, a couple of formulas (sum, if) and formatting on the currency and dates.

I've tried several methods to get my excel reports to work: First I left the excel workbook in the "en-US" culture and tried simply chaging the number format for Brazil to:

_-[$R$-416] * #.##0,00_-;-[$R$-416] * #.##0,00_-;_-[$R$-416] * "-"??_-;_-@_-

And this formatted the regular cells but the formulas still failed to show a value. Instead they showed a 0 value.

Next I tried changing the workbook to the "pt-BR" culture and that also forced me to translate the formula names (Sum -> Soma, If -> Se) but they still wouldn't should a value and instead showed a #Name/#Nome error. Interestingly enough the formulas would work if I edited the cell and hit enter. The formula wouldn't change but it would some how fix that cell.

I need to be able to out excel reports that can format dates/currencies and apply simple formulas (IF, Sum) for other excel cultures.

View 1 Replies

Accessing Excel 2010 (xlsx) Spreadsheet?

Feb 24, 2011

I would like to access an Excel 2010 spreadsheet via ASP.NET 4 - what is the best (i.e. straight forward) method to do this? I would like to update the spreadsheet via ASP then read the results of the data from Excel back to a web form.

View 9 Replies

Exporting Gridview Contents To Excel Spreadsheet?

Feb 25, 2010

I have a gridvidew (GV2). I want the user to be able to export the contents of this gridview to an excel spreadsheet for offline processing.

Here is my subroutine:

[code]...

On clicking the ExcelButton I get the error message:

Control 'GV2' of type 'GridView' must be placed inside a form tag with runat=server.

The control GV2 is in fact inside:

<form id="form1" runat="server"></form>

View 1 Replies

Copy And Paste From An Excel Spreadsheet To A Control?

Oct 21, 2010

I would like to be able to copy one row and five columns from an Excel spreadsheet to a table like structure on a ASP.NET web form. The idea is keeping the data in the exact row and column from Excel to the table like control on the ASP.NET web-form. Then I want to be able to save to the contents of the ASP.NET control to a database by a buttoon command click. What ASP.NET control would allow me to do this? Gridviews and datagrids don't seem to allow me to do this.

View 1 Replies

C# - Generate And Email An Excel Spreadsheet Without Saving It?

Mar 3, 2011

My host does not allow me to save files to the file system, but I would like to be able to send some reports via email as Excel attachments.

How can I generate and the file without actually saving it to disk?

View 2 Replies

How To Show Information From An Excel Spreadsheet In A Web Page

Jun 10, 2010

I want to show information from an excel spreadsheet in a web page. The xls will have maybe 5 columns, and as many rows as needed. The columns will be 'Name', 'Created Date', 'Expired Date', 'Owner', and maybe down the road maybe more.

What I would like is for the C# to nightly read the xls, and display the information in a table on the website.

If there is a PDF available for download I am going to link that as well.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved