【问题标题】:Show images in RDLC from URL using C# Visual Studio使用 C# Visual Studio 从 URL 显示 RDLC 中的图像
【发布时间】:2019-02-15 03:06:37
【问题描述】:

我想导出带有图像的报告。存储的图像在 DB 中是 URL 格式。

我的替代方法是物理下载文件并传递文件路径以显示图像,但这种方式似乎是多余的。 Sample from here

最好的方法是什么?非常感谢!

【问题讨论】:

  • 我尝试直接将完整的 URL 作为值,但它没有显示任何内容。我正在使用 Visual Studio 构建 RDLC,我需要为此授予任何权限吗?我配置了 ReportViewer1.LocalReport.EnableExternalImages = true;还有什么?
  • 这不起作用的原因是因为我的 URL 的 Content-Type 设置为 Content-Type: application/octet-stream,而不是 Content-Type: image/jpeg。因此,它不会显示在报告中。

标签: c# reporting-services rdlc


【解决方案1】:

我最终使用下面的代码下载图像并将其转换为 base64,然后在 RDLC 中显示。

var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData(urlimg);

DataRow drow = table.NewRow();

drow["filepath"] = Convert.ToBase64String(imageBytes);

RDLC 配置如下图。

【讨论】:

    猜你喜欢
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-03
    • 2016-06-04
    • 2021-08-23
    • 1970-01-01
    • 2016-12-19
    相关资源
    最近更新 更多