I have code that uses an XSL stylesheet to transform a dataset into a file that MS Excel can read. Below is a simplified version of the code. This works..for the most part. It sucessfully sends the excel file to the client, but only if the client saves it to thier HD can they open it. If they click the open button (instead of Save As), Excel opens and says it cannot find the file.
Any Ideas??
protected void Page_Load(Object sender, EventArgs e)
{
Database db = new Database();
String ls_file;
//db.ApplicantsBySpecialty returns valid dataset
ls_file = DataSetTransform(db.ApplicantsBySpecialty("aspecia lty"), Server.MapPath("Styles/Excel.xsl"));
db = null;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-disposition", "attachment; filename=\"excel.xls\"");
Response.Charset = "";
Response.Write(ls_file);
Response.Flush();
Response.End();
}
public string DataSetTransform(DataSet ds, String as_stylesheet_path)
{
XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
StreamReader reader = new StreamReader(as_stylesheet_path);
XmlTextReader xRdr = new XmlTextReader(reader);
xt.Load(xRdr, null, null);
StringWriter sw = new StringWriter();
xt.Transform(xmlDataDoc, null, sw, null);
xmlDataDoc = null;
xt = null;
sw.Close();
reader.Close();
xRdr.Close();
return sw.ToString();
}