VS2010 ReportViewer导出文件下载保存不能识别文件类型

今天测试项目时,突然发现导出报表下载保存的保存,不能识别文件的类型,文件名称为:.xls[3]

检查代码发现在指定报表路径时多了一个方法:

ReportViewer1.LocalReport.LoadReportDefinition(GenerateRdlc(dic["reportXml"]));

  public MemoryStream GenerateRdlc(string xmlName)
        {
            XmlDocument sourceDoc = new XmlDocument();
            string path = AppDomain.CurrentDomain.BaseDirectory + xmlName + "";
            sourceDoc.Load(path);
            MemoryStream ms = new MemoryStream();
            XmlSerializer serializer = new XmlSerializer(typeof(XmlDocument));
            serializer.Serialize(ms, sourceDoc);
            ms.Position = 0;
            return ms;
        }

画蛇添足,把这个方法去掉再试,OK了

ReportViewer1.LocalReport.ReportPath = dic["reportXml"];

顺便给的导出的文件设置名称:

ReportViewer1.LocalReport.DisplayName = “测试文件名”;

原文地址:https://www.cnblogs.com/yuking/p/3455874.html