Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2006, 05:17 PM
Authorized User
 
Join Date: Jun 2003
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default HttpResponse response problem???

hi i´m trying to use the code below to save a dataset in a excell format. But the response object is not recognized.

Anybody can help me...

Thanks

public void ConvertXLS(DataSet ds)
        {

            //first let's clean up the response.object
            response.Clear();
            response.Buffer = true;
            response.Charset = "";
            response.AddHeader("Content-Disposition", "attachment;filename=Report.xls");

            //set the response mime type for excel
            response.ContentType = "application/vnd.ms-excel";

            //create a string writer
            System.IO.StringWriter stringWrite;
            stringWrite=new System.IO.StringWriter();

            //create an htmltextwriter which uses the stringwriter
            System.Web.UI.HtmlTextWriter htmlWrite;
            htmlWrite=new System.Web.UI.HtmlTextWriter(stringWrite);
            //instantiate a datagrid
            System.Web.UI.WebControls.DataGrid dg=new System.Web.UI.WebControls.DataGrid();
            //set the datagrid datasource to the dataset passed in
            dg.DataSource = ds.Tables[0];
            //bind the datagrid
            dg.DataBind();
            //tell the datagrid to render itself to our htmltextwriter
            dg.RenderControl(htmlWrite);
            //all that's left is to output the html
            response.Write(stringWrite.ToString());
            response.End();
        }
 
Old February 22nd, 2006, 08:28 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Where are you trying to use this function?

If your using it anywhere outside the main aspx page you'll need to define the HttpContext for the Response object.

e.g. Context.Response.Clear();

See the following link for more details:
http://msdn.microsoft.com/library/de...ntexttopic.asp

- A.Kahtava





Similar Threads
Thread Thread Starter Forum Replies Last Post
Response.AddHeader Problem kwilliams Classic ASP Professional 6 November 13th, 2007 06:26 PM
httpresponse in console application in VB.NET 1.1 bhavna VS.NET 2002/2003 1 March 21st, 2007 06:30 AM
Problem with response.sendredirect urbuddie JSP Basics 0 September 15th, 2005 02:38 PM
Problem with Response.ContentType nagesh_vasa XML 1 May 23rd, 2004 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.