I have a web form page that is supposed to be able to write content of a Crystal Report out to either a pdf or excel document depending on which selection a user makes.
I've got 2 problems:
- For both .pdf and .xls extensions, there is a bracket with a one inside it being appended to the extension IE: fileName.xls[1]
- If a user selects an excel document, in IE the file download prompt appears and asks if we want to save or open the file:
- Name: .xls[1]
- Type: HTML Document, 19 kb
- From localhost
The PDF File saves just fine, however if we choose to open the excel file, it opens an Explorer window and we get garbage...
Here's our code:
fs = File.Open(output, FileMode.Open, FileAccess.Read);
byte[] byteArray = new byte[fs.Length];
fs.Read(byteArray, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachments;filename=" + fileName + "." + extn);
Response.AddHeader("Content-Length", byteArray.Length.ToString());
switch ("." + extn)
{
case ".pdf":
Response.AppendHeader("Content-Type", "application/pdf");
break;
case ".xls":
Response.AppendHeader(".xls", "application/excel");
break;
case ".txt":
Response.AppendHeader("Content-Type", "application/notepad");
break;
}I've confirmed that these extensions are free from the [1] throughout the code..
It's my guess that somthing's going on with the content headers.
Thanks.
Doug