SSRS Report Export to Excel Shows Content Warning

Akshayaa Kalyanavenkatesh 60 Reputation points
2025-08-29T06:01:53.6166667+00:00

Hello,

In our application, while trying to open an SSRS report exported to Excel, we are getting the following warning message:

“We found a problem with some content in excelfilename.xlsx. Do you want us to recover as much as we can? If you trust the source of this workbook, click Yes.”

Details:

Application is built using Visual Studio .NET and SQL Server Reporting Services (SSRS).

The same report, when exported to Excel directly from Report Manager, opens without any warning.

The issue only occurs when exporting through our custom application.

Question:
What could be causing this warning when exporting reports from the application, and how can we fix it so the Excel file opens cleanly without the recovery prompt?

In the code below, I attempted to validate the file contents. The file starts with 'PK', and it is also being exported successfully.

protected void btnDownload_Click(object sender, EventArgs e)

{

 string format = ddlExportFormat.SelectedValue;

 if (string.IsNullOrEmpty(format))

     return;

 string mimeType, encoding, extension;

 string[] streamids;

 Warning[] warnings;

 try

 {

     string deviceInfo = null;

     if (format.Equals("EXCELOPENXML", StringComparison.OrdinalIgnoreCase))

         deviceInfo = "<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>";

     byte[] bytes = ReportViewer1.ServerReport.Render(

         format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);

     WriteLog($"Exported bytes length: {bytes?.Length ?? 0}");

     if (warnings != null && warnings.Length > 0)

     {

         foreach (var w in warnings)

             WriteLog($"Export warning: {w.Message}");

     }

     string textContent = System.Text.Encoding.UTF8.GetString(bytes);

     WriteLog("First 200 chars of export: " + textContent.Substring(0, Math.Min(200, textContent.Length)));

     string fileExtension = extension;

     if (format.Equals("EXCELOPENXML", StringComparison.OrdinalIgnoreCase))

         fileExtension = "xlsx";

     if (format.Equals("WORDOPENXML", StringComparison.OrdinalIgnoreCase))

         fileExtension = "docx";

     string safeName = Regex.Replace(Name, @"[^\w\-. ]", "_");

     string fileName = $"{safeName}.{fileExtension}";

     Response.Clear();

     Response.ClearHeaders();

     Response.ClearContent();

     Response.ContentType = mimeType;

     Response.AddHeader("Content-Disposition", $"attachment; filename=\"{fileName}\"");

     Response.BinaryWrite(bytes);

     Response.Flush();

     HttpContext.Current.ApplicationInstance.CompleteRequest();

 }

 catch (Exception ex)

 {

     WriteLog($"Export error: {ex}");

 }

}

Thanks,
Akshayaa

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.