protected void btnSaveUsingStream_Click(object sender, EventArgs e)
{
// ExStart:SaveExcelFileUsingStream
// Generates a temporary file name.
string filename = Session.SessionID + "_out.xls";
string path = (this.Master as Site).GetDataDir() + "\\GridWebBasics\\";
FileStream fs = File.Create(path + filename);
// Saving Grid content of the control to a stream
GridWeb1.SaveToExcelFile(fs);
// Closing stream
fs.Close();
// Sents the file to browser.
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + filename);
Response.WriteFile(path + filename);
Response.End();
// ExEnd:SaveExcelFileUsingStream
}