Dear Indrish,
Please try following :
FileStream fs = new FileStream(Excelpath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
fs.Close();
fs.Dispose();
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
GridView1.RenderControl(htw);
File.WriteAllText(Excelpath, sw.ToString());
htw.Close();
}
sw.Close();
}
Hope, this will help.
Regards
Aman