SSRS - 外部图片无法在HTML报告中呈现

时间:2017-11-01 13:45:41

标签: reporting-services sql-server-2012 ssrs-2012

我正在研究SSRS报告。我有一个嵌入了外部图像的报告 这在报表查看器中呈现得很好。

但是当我通过网址在我的应用程序中呈现HTML 4.0格式的报告时(不使用报告查看器)。从图像以外的所有数据返回的报告不在html中

看到图片标签如下所示: -

<img onerror="this.errored=true;" class="r1" src="http://ges-server-pc/ReportServer_SQLEXPRESS?%2FGES-MVC%2FGES_FWCR&amp;rs%3ASessionID=vdpuofii3xtph545xelnym45&amp;rs%3AFormat=HTML4.0&amp;rs%3AImageID=1403af250c474da8a5f851b63a8a377b">

如何在报表上呈现格式= HTML 4.0

的extrenal图像

任何人都能有相同的解决方案吗会很明显

提前致谢

1 个答案:

答案 0 :(得分:0)

这是确保您的应用程序可以可靠地显示SSRS在报表中动态呈现的图像的一种方法。

当您使用报表查看器控件时,在幕后进行了大量操作以保持活动会话并允许访问由用户请求的报表生成的所有工件。当您直接使用ReportExecution api时,会有一些不受支持的高级报告功能。交互式排序,大小调整,深入分析和此问题仅举几例。

始终确保客户可以使用报告中的动态图像非常简单。我不得不跨过这个障碍,我将分享我解决它的方式。

简而言之,您将不得不拦截渲染,迭代流,并将每个资源保存到临时文件夹,并告诉ssrs在您的结束的Web应用程序后面的临时文件夹中查找该图像用户已通过。

进行身份验证

<强> DeviceInfo

设备信息结构,大多被忽视,将派上用场。在此结构中,您将找到 StreamRoot 属性。你可以找到这方面的文件。它基本上允许您覆盖SSRS根据需要流式传输资源的位置。这就是您告诉SSRS在新位置查找外部图像的方法。

对于渲染的每个报告,我在渲染之前使用guid创建临时文件夹。此外,在渲染之前,您需要将StreamRoot设置为此临时文件夹。

string physicalTempFolder = MakeNewTempFolderInTempOffOfWebRoot();
string virtualTempFolder = Path.Combine(yourWebRoot,"Temp",Path.GetDirectoryName(physicalTempFolder));

现在您有一个指向您的仓库的物理和虚拟指针,其中将保存图像以用于报告。现在更新SSRS中的StreamRoot。这告诉SSRS我们想要覆盖动态图像的默认位置等等。

StringBuilder devInfo = new StringBuilder();
if (YourRenderFormat=="HTML")
{
    devInfo.Append("<DeviceInfo>");
    devInfo.Append("<StreamRoot>" + virtualTempFolder+ "</StreamRoot>");  
    devInfo.Append("</DeviceInfo>");       
}

使用所需的设备信息结构构建,我们可以将其传递给render方法。

string extension;
string mimeType;
string reportEncoding;
string[] streamIDs = null;
ReportExecution2005.Warning[] warnings = null;            

ReportExecution2005.ExecutionHeader execHeader = new ReportExecution2005.ExecutionHeader();
ReportExecution2005.ExecutionInfo rpt = _execService.LoadReport(YourReportPath, null);

if(YourParamas!=null)
    _execService.SetExecutionParameters(YourParams, "en-us");
_execService.ExecutionHeaderValue = execHeader;
_execService.ExecutionHeaderValue.ExecutionID = rpt.ExecutionID;

result = _execService.Render(format, devInfo.ToString(), out extension, out mimeType, out reportEncoding, out warnings, out streamIDs);

render方法返回streamIDs out参数,它在这里是关键。在我们调用render之后,只需迭代所有图像流并调用ssrs的RenderStream()方法来获取图像并保存到物理临时文件夹。

if (YourRenderFormat=="HTML"))
{

    string imageEncoding = "";               
    // For each image stream returned by the call to render,
    // render the stream and save it to the application root
    string FilePath = physicalTempFolder;
    byte[] image;
    // For each image stream returned by the call to render,
    // render the stream and save it to the application root
    foreach (string streamID in streamIDs)
    {
        image = _execService.RenderStream("HTML4.0", streamID, null, out imageEncoding, out mimeType);
        //All files are unique
        File.WriteAllBytes(Path.Combine(physicalTempFolder,streamID),image);
    }
}
return result;