473,382 Members | 1,512 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,382 software developers and data experts.

Generate Excel and then redirect to another page

Hi, i'm exporting gridview data to excel file, and after that (after
the save as dialog pops up on client machine) i need the page to be
redirected to home page. Tha problem it's that the export rutine ends
with response.end, and anything else after that it's ignored, and if i
put the redirect command in the finally it says that http headers had
already been sent to the client, so that's not working eather. Ideas?
This is my code.

protected void Page_Load(object sender, EventArgs e)
{
Session["endWait"] = "SI";
long id = 0;

CERTIFICADO oCertificado = new CERTIFICADO();
DataTable dt;

try
{
string s =
System.Globalization.CultureInfo.CurrentCulture.Da teTimeFormat.ShortDatePattern;
DateTime fecha =
System.DateTime.Parse(Request["FechaVencimiento"].ToString(),
System.Globalization.CultureInfo.CurrentCulture.Da teTimeFormat);
dt = oCertificado.GenerarCertificados(Request["Letra"],
Request["Cantidad"], oCertificado.GetSerie(),
Request["FechaVencimiento"], Session["id_usuario"].ToString(), ref id);

Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=Certificados" +
System.DateTime.Today.ToString(s).Replace('/', '-') + "-" +
System.DateTime.Now.Hour + "_" + System.DateTime.Now.Minute + "_" +
System.DateTime.Now.Second + ".xls");

Response.ContentType = "application/vnd.xls";

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
CERTIFICADO c = new CERTIFICADO();
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
finally
{
oCertificado = null;
}
}

public override void VerifyRenderingInServerForm(Control control)
{
}

Jul 10 '06 #1
0 1208

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

Similar topics

9
by: Rich | last post by:
Hi, I have a bunch of Excel reports that I would like to display on my company's intranet. The reports contain priviledged information, however. My plan was to have a page with a dropdown box...
3
by: Michael | last post by:
Hi All, I am using win2k advance sever, IIS + ASP + Office 2000 +SQL server 2000 I have a internal web site, running on IIS. it is for internal reporting purpose. All the ASP web pages are...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
1
by: | last post by:
The following code: Private Sub ClearControls(ByVal ctrl As Control) Dim i As Int32 For i = ctrl.Controls.Count - 1 To 0 Step -1 ClearControls(ctrl.Controls(i))
2
by: Chris | last post by:
I'm using an article "http://www.dotnetjohn.com/articles.aspx?articleid=36" to create an exported excel doucment, it works great expect when I placed an reponse.write catch error on his try/catch I...
5
by: Stephen | last post by:
Hi, I am converting webpage to Excel and its within a try catch block it creates an Excel Spreadsheet but at the sametime it gives this error ExceptionMessage:Thread was being aborted. Please...
2
by: Peter S. | last post by:
I have an ASP.NET page that invokes a web control written in C#. What I want to do is (based on the session ID) display a certain spreadsheet that exists on a network drive. I want the webcontrol...
4
by: Amirallia | last post by:
Hello Here's my code to export a datagrid to Exel : Response.Clear() Response.Buffer = True Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Dim monStringWriter As...
18
by: Paul Lautman | last post by:
JRough wrote: What do you mean by "redirect the output to Excel"??? Excel isn't a location, it's a spreadsheet program that some (but not all users) will have on their machine. BTW, Location:...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.