Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Webform/Crystal Reports File Output for .pdf/.xls

$
0
0

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:

  1. For both .pdf and .xls extensions, there is a bracket with a one inside it being appended to the extension IE: fileName.xls[1]
  2. 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


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>