无法将System.IO.Stream隐式转换为System.IO.MemoryStream。 C#

时间:2019-03-12 06:39:38

标签: c# casting crystal-reports

此代码用于在VB中工作,无法查明我在这里缺少什么。

System.IO.MemoryStream oStream = new System.IO.MemoryStream();

if (rptName == "rpt_BankFormatExCopy.rpt" | rptName == "GIS_reportExFormat.rpt" | rptName == "GPFDeductionRepExFormat.rpt")
    oStream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.ExcelRecord);
else
    oStream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);

1 个答案:

答案 0 :(得分:0)

看起来rptObjectStream

在这种情况下,您可以只使用CopyTo

var oStream = new MemoryStream();
Stream stream = null;

if (rptName == "rpt_BankFormatExCopy.rpt" | rptName == "GIS_reportExFormat.rpt" | rptName == "GPFDeductionRepExFormat.rpt")
    stream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.ExcelRecord);
else
    stream = rptObject.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);

stream.CopyTo(oStream);