Extract Data from a Web Page into an Excel Spreadsheet Using ASP.Net Application and
Excel file save Automaticaly in our Application.Following are detail what i wanti Create a web application in that application their are some link when we click on that link and redirect on contact page the contact details are store automaticaly in excel
Extract Data from a Web Page into an Excel Spreadsheet Using ASP.Net Application and
Excel file save Automaticaly in our Application

Rahul BansalRank #143 · 15.9K reputationPosted Mar 17, 2015, 1:46 AM EDT
using System.IO;
public void expgrid()
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=RepeaterExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
Page.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
Vishnu BhangaleRank #9,687 · 203 reputationPosted Mar 17, 2015, 1:53 AM EDT
My Question is not to upload the excel file in application my question is to store the web page content in excel file using .net and this will be done when i click on any other link that are in my application ex.suppose i click on google.com then google page will open and the content of google page will save in excel this will be done automaticaly after i click on link.
Vishnu BhangaleRank #9,687 · 203 reputationPosted Mar 17, 2015, 1:57 AM EDT
Your code is only open blank excel file
Rahul BansalRank #143 · 15.9K reputationPosted Mar 17, 2015, 2:03 AM EDT
I will try to extract the other website to excel.
Rahul BansalRank #143 · 15.9K reputationPosted Mar 17, 2015, 2:14 AM EDT
http://www.c-sharpcorner.com/UploadFile/ankurmalik123/export-html-to-excel-and-more/
Vishnu BhangaleRank #9,687 · 203 reputationPosted Mar 17, 2015, 2:15 AM EDT
You are correct but when i call it on page load the blank excel will generate please give me full code.
Eugene Montes24 reputationPosted Mar 19, 2015, 12:01 AM EDT
Now the main thing here is the "Page.RenderControl(hw)" call which will retrieve the actual HTML representation of some web control (in this case the Page), but in order to successfully call this method you need override the "VerifyRenderingInServerForm", like the following:
public override void VerifyRenderingInServerForm(Control control) { }
And also you need to disable "EnableEventValidation" on the Page, like the following:
<%@ Page EnableEventValidation="false" ...
In case you need a real excel file then you will have to use some other approach, note that you can find some .NET libraries that can help you out with this.
For example you can try out this Excel library for .NET, it can convert the HTML content into an excel file in .NET and then you can export that excel file in ASP.NET.