XLS DataSet to Excel will not open unless saved

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    XLS DataSet to Excel will not open unless saved

    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(Objec t sender, EventArgs e)
    {
    Database db = new Database();

    String ls_file;

    //db.ApplicantsBy Specialty returns valid dataset
    ls_file = DataSetTransfor m(db.Applicants BySpecialty("as pecialty"), Server.MapPath( "Styles/Excel.xsl"));

    db = null;

    Response.Conten tType = "applicatio n/vnd.ms-excel";
    Response.AddHea der("Content-disposition", "attachment ; filename=\"exce l.xls\"");
    Response.Charse t = "";
    Response.Write( ls_file);
    Response.Flush( );
    Response.End();

    }

    public string DataSetTransfor m(DataSet ds, String as_stylesheet_p ath)
    {
    XmlDataDocument xmlDataDoc = new XmlDataDocument (ds);
    XslTransform xt = new XslTransform();
    StreamReader reader = new StreamReader(as _stylesheet_pat h);
    XmlTextReader xRdr = new XmlTextReader(r eader);

    xt.Load(xRdr, null, null);

    StringWriter sw = new StringWriter();
    xt.Transform(xm lDataDoc, null, sw, null);

    xmlDataDoc = null;
    xt = null;
    sw.Close();
    reader.Close();
    xRdr.Close();

    return sw.ToString();
    }
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    #2
    I found my problem, It was actually an inherited property that set

    Code:
    Response.CacheControl = "no-cache";
    Removed that line and everything worked fine

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      Originally posted by ShadowLocke
      I found my problem, It was actually an inherited property that set

      Code:
      Response.CacheControl = "no-cache";
      Removed that line and everything worked fine
      Thanks for posting your solution!

      Jared

      Comment

      Working...