Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my I want to export data from gridview to excel which including the master page
Posted
Comments
Aman4.net 22-Aug-11 7:40am    
Please mark as answer if any of following helped you.

Dear Indrish,

Please try following :

//Create or Open File using File Stream with ReadWrite Mode and Access.
FileStream fs = new FileStream(Excelpath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

fs.Close();
fs.Dispose();

//Use String Writer to Write Html in File
using (StringWriter sw = new StringWriter())
{

   //Use HTML Writer to fill Html Rendering Script in StringWriter  in File
   using (HtmlTextWriter htw = new HtmlTextWriter(sw))
   {

     //Render Gridview in HTML Writer 
     GridView1.RenderControl(htw);

     //Write all text in File using String Writer
     File.WriteAllText(Excelpath, sw.ToString());
     htw.Close();
   }
   sw.Close();
}


Hope, this will help.

Regards
Aman
 
Share this answer
 
v3
Check this[^]


and

This[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900