找回密码
 立即注册

QQ登录

只需一步,快速开始

penley
金牌服务用户   /  发表于:2020-11-30 20:56  /   查看:2648  /  回复:3
本帖最后由 penley 于 2020-12-1 19:48 编辑

环境:AR14、.net core mvc项目、JSViewer。

一、项目根目录创建Reports文件夹,用于保存所有报表文件,计划不同的报表文件放在此文件夹下的不同子文件夹中(按模块分)。
比如,有一个“演示报表.rdlx”的路径如下:
  1. Reports/ReportDemo/演示报表.rdlx
复制代码
并且,所有报表文件属性设置为“始终复制”,保证可以随应用一起发布。

二、MVC项目的Startup.cs中,设置报表文件根为Reports文件夹。
  1.               settings.UseFileStore(new DirectoryInfo("Reports"));
复制代码


三、在JSViewer中加载报表
  1. var viewer = GrapeCity.ActiveReports.JSViewer.create({
  2.         element: '#viewerContainer',
  3.         reportID: 'ReportDemo/演示报表.rdlx'
  4. });
复制代码


如果使用MVC项目直接启动, 是可以找到报表文件的,一切正常。但使用IIS Express启动项目,就无法找到报表。
类似如下:


注:如果把报表文件直接放在Reports文件夹下(无子文件夹),reportID指定为“演示报表.rdlx”,都是正常的。

四、尝试指定不同的路径,均以失败告终
1、演示报表.rdlx
2、Reports/ReportDemo/演示报表.rdlx
3、/Reports/ReportDemo/演示报表.rdlx
4、ReportDemo\\演示报表.rdlx
5、\\ReportDemo\\演示报表.rdlx
6、Reports\\ReportDemo\\演示报表.rdlx
7、\\Reports\\ReportDemo\\演示报表.rdlx

问题:
  reportID 参数到底需要传个什么样的格式?谢谢!!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

3 个回复

倒序浏览
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2020-12-1 10:25:07
沙发
你好, 个人建议ReportID写成这样的
  1. reportID: '演示报表.rdlx'
复制代码
这种格式是通用的,然后在后端Startup的方法中进行相对路径的匹配
你可以看看这个写法
  1. using System;
  2. using System.Data;
  3. using System.IO;
  4. using System.Threading.Tasks;
  5. using System.Web;
  6. using System.Web.Routing;
  7. using System.Windows.Media.Imaging;
  8. using GrapeCity.ActiveReports;
  9. using GrapeCity.ActiveReports.Aspnet.Viewer;
  10. using Microsoft.Owin;
  11. using Owin;

  12. [assembly: OwinStartup(typeof(JSviewerDatasource.Startup1))]

  13. namespace JSviewerDatasource
  14. {
  15.     public class Startup1
  16.     {
  17.         public static string EmbeddedReportsPrefix = "JSdatasource";
  18.         string ReportName = "";
  19.         public object GetReport(string P)//获取报表名称和报表参数,进行一个对应的报表名称和参数的分割
  20.         {
  21.             //string reportName = P.Split(';')[0];//报表名称;
  22.             //string parameter1 = P.Split(';')[1];//参数1;
  23.             //string parameter2 = P.Split(';')[2];//参数2;
  24.             string reportName = P;//报表名称;
  25.             PageReport rep = new PageReport();
  26.             string path = System.Web.Hosting.HostingEnvironment.MapPath("~/");
  27.             rep.Load(new FileInfo(@"" + path + "Reports/" + reportName));         
  28.             return rep.Report;
  29.            
  30.         }

  31.         public void Configuration(IAppBuilder app)
  32.         {
  33.         
  34.             app.UseReporting(settings =>
  35.             {
  36.                 settings.UseCompression = true;
  37.                 settings.UseCustomStore(GetReport);//使用UseCustomStore来自定义一些需要的值
  38.                 //settings.UseFileStore(new DirectoryInfo(String.Format(@"{0}.\Reports", HttpRuntime.AppDomainAppPath)));               
  39.                 settings.LocateDataSource = args =>
  40.                 {
  41.                     DataTable dt = new DataTable();
  42.                     string name = ReportName;
  43.                     //var p = args.Parameters[0].Value.ToString();
  44.                     if (args.DataSet.Query.DataSourceName == "DataSource1")
  45.                     {                     
  46.                         if (args.DataSet.Name == "DataSet1")
  47.                         {
  48.                             dt.Columns.Add("产品编号");
  49.                             dt.Columns.Add("产品名称");
  50.                             dt.Columns.Add("单价");
  51.                             dt.Columns.Add("库存量");
  52.                             dt.Columns.Add("产地");
  53.                             dt.Rows.Add("A001", "苹果", 10, 300, "中国");
  54.                             dt.Rows.Add("A002", "葡萄", 20, 200, "中国");
  55.                             dt.Rows.Add("A003", "香蕉", 30, 400, "中国");
  56.                             dt.Rows.Add("A004", "甘蔗", 10, 300, "中国");
  57.                             dt.Rows.Add("A005", "荔枝", 20, 200, "中国");
  58.                             dt.Rows.Add("A006", "芒果", 30, 400, "中国");
  59.                             dt.Rows.Add("A007", "猕猴桃", 110, 300, "中国");
  60.                             dt.Rows.Add("A008", "柠檬", 210, 200, "中国");
  61.                             dt.Rows.Add("A009", "栗子", 320, 400, "中国");
  62.                             dt.Rows.Add("A010", "火龙果", 100, 300, "中国");
  63.                             dt.Rows.Add("A011", "青芒", 250, 200, "中国");
  64.                             dt.Rows.Add("A012", "巴旦木", 320, 200, "中国");
  65.                             dt.Rows.Add("A013", "土豆", 380, 400, "中国");
  66.                             dt.Rows.Add("A014", "苹果", 110, 300, "中国");
  67.                             dt.Rows.Add("A015", "葡萄", 420, 200, "中国");
  68.                             dt.Rows.Add("A016", "香蕉", 530, 400, "中国");
  69.                             dt.Rows.Add("A017", "土豆", 380, 400, "中国");
  70.                             dt.Rows.Add("A018", "苹果", 110, 300, "中国");
  71.                             dt.Rows.Add("A019", "葡萄", 420, 200, "中国");
  72.                             dt.Rows.Add("A020", "香蕉", 530, 400, "中国");
  73.                             dt.Rows.Add("A021", "苹果", 10, 300, "中国");
  74.                             dt.Rows.Add("A022", "葡萄", 20, 200, "中国");
  75.                             dt.Rows.Add("A023", "香蕉", 30, 400, "中国");
  76.                             dt.Rows.Add("A024", "甘蔗", 10, 300, "中国");
  77.                             dt.Rows.Add("A025", "荔枝", 20, 200, "中国");
  78.                             dt.Rows.Add("A026", "芒果", 30, 400, "中国");
  79.                             dt.Rows.Add("A001", "苹果", 10, 300, "中国");
  80.                             dt.Rows.Add("A002", "葡萄", 20, 200, "中国");
  81.                             dt.Rows.Add("A003", "香蕉", 30, 400, "中国");
  82.                             dt.Rows.Add("A004", "甘蔗", 10, 300, "中国");
  83.                             dt.Rows.Add("A005", "荔枝", 20, 200, "中国");
  84.                             dt.Rows.Add("A006", "芒果", 30, 400, "中国");
  85.                             dt.Rows.Add("A007", "猕猴桃", 110, 300, "中国");
  86.                             dt.Rows.Add("A008", "柠檬", 210, 200, "中国");
  87.                             dt.Rows.Add("A009", "栗子", 320, 400, "中国");
  88.                             dt.Rows.Add("A010", "火龙果", 100, 300, "中国");
  89.                             dt.Rows.Add("A011", "青芒", 250, 200, "中国");
  90.                             dt.Rows.Add("A012", "巴旦木", 320, 200, "中国");
  91.                             dt.Rows.Add("A013", "土豆", 380, 400, "中国");
  92.                             dt.Rows.Add("A014", "苹果", 110, 300, "中国");
  93.                             dt.Rows.Add("A015", "葡萄", 420, 200, "中国");
  94.                             dt.Rows.Add("A016", "香蕉", 530, 400, "中国");
  95.                             dt.Rows.Add("A017", "土豆", 380, 400, "中国");
  96.                             dt.Rows.Add("A018", "苹果", 110, 300, "中国");
  97.                             dt.Rows.Add("A019", "葡萄", 420, 200, "中国");
  98.                             dt.Rows.Add("A020", "香蕉", 530, 400, "中国");
  99.                             dt.Rows.Add("A021", "苹果", 10, 300, "中国");
  100.                             dt.Rows.Add("A022", "葡萄", 20, 200, "中国");
  101.                             dt.Rows.Add("A023", "香蕉", 30, 400, "中国");
  102.                             dt.Rows.Add("A024", "甘蔗", 10, 300, "中国");
  103.                             dt.Rows.Add("A025", "荔枝", 20, 200, "中国");
  104.                             dt.Rows.Add("A026", "芒果", 30, 400, "中国");
  105.                         }                       
  106.                     }                 
  107.                     return dt;
  108.                 };


  109.             });

  110.         }      
  111.     }
  112. }
复制代码


回复 使用道具 举报
penley
金牌服务用户   /  发表于:2020-12-1 19:48:12
板凳
好的,谢谢!我试试。
回复 使用道具 举报
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2020-12-1 20:00:52
地板
好的,你试试,有问题随时沟通
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部