473,414 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

XLS DataSet to Excel will not open unless saved

115 100+
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();
}
Feb 14 '08 #1
2 1996
ShadowLocke
115 100+
I found my problem, It was actually an inherited property that set

Expand|Select|Wrap|Line Numbers
  1. Response.CacheControl = "no-cache";
Removed that line and everything worked fine
Feb 14 '08 #2
jhardman
3,406 Expert 2GB
I found my problem, It was actually an inherited property that set

Expand|Select|Wrap|Line Numbers
  1. Response.CacheControl = "no-cache";
Removed that line and everything worked fine
Thanks for posting your solution!

Jared
Feb 19 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: magnus | last post by:
Hi I´m trying to export a datatable to Excel. So far I have set up a file dump and can start Excel to read from that file. Now, my question is this: Since I have a stream, could I convert it to...
3
by: VbUser25 | last post by:
hi.. i have a form i accept some user inputs in the form. there is a link on the form from where i open the excel file in the same browser (not in a new page...simply using a href. i am also...
9
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save...
4
by: Hans [DiaGraphIT] | last post by:
Hi! I want to export a dataset to an excel file. I found following code on the net... ( http://www.codeproject.com/csharp/Export.asp ) Excel.ApplicationClass excel = new ApplicationClass();...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
10
by: Esmael | last post by:
Hi to all, /*****************************/ OS-WIn XP SP2 VB6 SP6 /*****************************/ Is their anyone who can help me with this: Source code written on VB6.
1
by: need2know | last post by:
I operate a small business where i need to prepare Quotations, Invoices and Delivery forms. I am using Microsoft Office Excel. I would like to get some help to auto number these forms If i open...
4
by: JaxDawg | last post by:
I have a spreadsheet saved as an XML spreadsheet so I can manipulate it easier (and don't need COM). When I'm done, I want to display to the user. Currently, I'm using simple JavaScript in my PHP...
1
by: =?Utf-8?B?Y29uc3RhbnRpbg==?= | last post by:
I have problem with my code I need to read from Excel worksheet into dataset the problem is in this line oleda.Fill(ds). The data adapter should fill dataSet with data from Excel worksheet but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.