Problems with Office 2007

Everything worked fine in Office 2003, but with Office 2007 we get the following error when we try to open the Excel file.

"The file you are trying to open, 'ReportingHandler.aspx', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

In ReportHandler.aspx we are using the following lines to open:

private void GenerateExcelReport()

{

if(IsUserPrompted)

{

current.Response.AppendHeader("Content-disposition",

string.Format("attachment;filename={0}.xls", ReportName));

}

else

{

current.Response.AppendHeader("Content-disposition",

string.Format("inline;filename={0}.xls", ReportName));

}

current.Response.ContentType = "application/vnd.ms-excel";

WriteStream();

}

private void WriteStream()

{

MemoryStream stream = (MemoryStream)ReportCache;

current.Response.Buffer = true;

current.Response.BinaryWrite(stream.ToArray());

stream.Close();

SessionManagement.ViewBaseSession.Remove(ReportId);

}

If you click "Yes" on the warning then the Excel looks fine. I have read others on the internet are having similar issues and that it might be an Office 2007 issue, but wanted to run it up the flag pole here to see if you all knew anything.

Please try following code:

private void GenerateExcelReport(bool isExcel2007)

{

if(IsUserPrompted)

{

if(isExcel2007)

{

current.Response.AppendHeader("Content-disposition",

string.Format("attachment;filename={0}.xlsx", ReportName));

}

else

{

current.Response.AppendHeader("Content-disposition",

string.Format("attachment;filename={0}.xls", ReportName));

}

}

else

{

if(isExcel2007)

{

current.Response.AppendHeader("Content-disposition",

string.Format("inline;filename={0}.xlsx", ReportName));

}

else

{

current.Response.AppendHeader("Content-disposition",

string.Format("inline;filename={0}.xls", ReportName));

}

}

if(isExcel2007)

current.Response.ContentType = "application/xlsx";

else

current.Response.ContentType = "application/vnd.ms-excel";

WriteStream();

}


Ok, I’ll give that a shot. But how do you determine the value of isExcel2007? Do you all have a standard way you recommend trying to detect Office 2007?

Didn't work, and in fact made it worse. Now I get the File Download dialog, and when I hit Open I get the original popup:

"Excel cannot open the file "ReportingHandler.aspx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

Then when I hit ok I get a new error:

"Excel cannot open the file "RiskMap[1].xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

When I hit ok on that message I get the File Download window again, but the Open button is now gone and there is a windows message at the bottom of the dialog:

"The file you are downloading cannnot be opened by the default program. It is either corrupted or have an incorrect file type. As a security precation, it is recommended that you cancel the download. Hoe can I decide what software to open?"

Hi,

Do you have MS Excel2007 installed on your pc. I think you do need to install it if you want to open / view the generated .xlsx file.

Thank you.

Yes, I have Office 2007 Professional installed on my PC, including Excel 2007.