telerik reporting 在.net core api 使用

工具要求:telerik reporting R3 2019、.net core 2.2  、vs2017 最新版

从官网下载下来的的telerik reporting 的.net core  例子是无法成功预览报表的,可能内部程序有问题,

 以下为正确操作步骤

1.打开nuget 包管理源,新建程序包源(https://nuget.telerik.com/nuget),如下:

telerik reporting 在.net core api 使用_第1张图片

 

 

2.切换程序包源,选择telerik reporting  安装包,如下:

telerik reporting 在.net core api 使用_第2张图片

 

3.api代码:

 1 namespace CSharp.AspNetCoreDemo.Controllers
 2 {
 3     using System.Collections.Generic;
 4     using System.IO;
 5     using System.Linq;
 6     using Microsoft.AspNetCore.Mvc;
 7     using Telerik.Reporting.Services;
 8     using Telerik.Reporting.Services.AspNetCore;
 9     using System.Net;
10     using System.Net.Mail;
11     using Telerik.Reporting.Cache.File;
12     using Microsoft.AspNetCore.Authorization;
13 
14     [Route("api/reports")]
15     public class ReportsController : ReportsControllerBase
16     {
17         readonly string reportsPath = string.Empty;
18 
19         public ReportsController(ConfigurationService configSvc)
20         {
21              
22             this.reportsPath = Path.Combine(configSvc.Environment.WebRootPath, "report");
23          
24             this.ReportServiceConfiguration = new ReportServiceConfiguration
25             {
26                 ReportingEngineConfiguration = configSvc.Configuration,
27                 HostAppId = "Html5DemoAppCore",
28                 Storage = new FileStorage(),
29                 ReportResolver = new ReportTypeResolver()
30                 .AddFallbackResolver(new ReportFileResolver(this.reportsPath)),
31             };
32         }
33 
34         [HttpGet("reportlist")]
35         public IEnumerable<string> GetReports()
36         {
37             //return Directory
38             //    .GetFiles(this.reportsPath)
39             //    .Select(path =>
40             //        Path.GetFileName(path));
41 
42 
43             List<string> list = new List<string>();
44 
45             foreach (var item in Directory.GetFiles(this.reportsPath))
46             {
47                 var fileName=  Path.GetFileName(item);
48                 list.Add(fileName);
49             }
50             return list;
51         }
52         protected override HttpStatusCode SendMailMessage(MailMessage mailMessage)
53         {
54             throw new System.NotImplementedException("This method should be implemented in order to send mail messages");
55             //using (var smtpClient = new SmtpClient("smtp01.mycompany.com", 25))
56             //{
57             //    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
58             //    smtpClient.EnableSsl = false;
59 
60             //    smtpClient.Send(mailMessage);
61             //}
62             //return HttpStatusCode.OK;
63         }
64        
65     }
66 }

 

4:前端代码

  1 
  2 "http://www.w3.org/1999/xhtml">
  3 
  4     Telerik HTML5 Report Viewer Demo
  5 
  6     "X-UA-Compatible" content="IE=edge" />
  7 
  8     "viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  9 
 10     
 11 
 12     "http://kendo.cdn.telerik.com/2018.2.620/styles/kendo.common.min.css" rel="stylesheet" id="common-css" />
 13     "http://kendo.cdn.telerik.com/2018.2.620/styles/kendo.blueopal.min.css" rel="stylesheet" id="skin-css" />
 14 
 15     
 16 
 17     
 18 
 19     
 41 
 42 
 43     <select id="theme-switcher">select>
 44 
 45     
"reportViewer1"> 46 loading... 47
48 49 112 113 114

 

5. 本人使用的是oracle ,所以是引用Oracle.ManagedDataAccess.Core ,这个dll 不需要按照oracle 的客户端。配置文件添加数据库连接

telerik reporting 在.net core api 使用_第3张图片

 

6. 若是想在报表设计器预览 又不想安装oracle 客户端,操作如下:

   1)修改设计器的Telerik.ReportDesigner.exe.config ,在connectionStrings 前添加以下内容









 

  2)在设计器Telerik.ReportDesigner.exe同级目录放入:

          Oracle.ManagedDataAccess.dll

  

源码 地址:https://download.csdn.net/download/h4715582/11956099

你可能感兴趣的:(telerik reporting 在.net core api 使用)