当前位置:首页 > Windows程序 > 正文

telerik reporting 在.net core 2 api 使用

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

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

以下为正确操作步骤

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

技术图片

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

技术图片

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 =http://www.mamicode.com/ 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=http://www.mamicode.com/ 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:前端代码

温馨提示: 本文由杰米博客推荐,转载请保留链接: https://www.jmwww.net/file/9987.html