需要如何才能动态更改,这个不是在应用启动时就确定的路径吗?
我的代码如下:
- private static readonly DirectoryInfo ResourcesRootDirectory = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "Reports/Resources" + Path.DirectorySeparatorChar));
- public static IApplicationBuilder UseReport(this IApplicationBuilder app)
- {
- //初始化报表配置
- ReportConfiguration.Instance.InitSettings();
- app.UseReportViewer(config => {
- //报表资源文件
- config.UseFileStore(ResourcesRootDirectory);
- config.LocateDataSource = args =>
- {
- //数据源类型,需要根据数据源类型返回对应的数据,例如:如果是Json类型,则需要返回Json类型的数据
- var dataSourceType = args.Report.DataSources[0].ConnectionProperties.DataProvider;
- var vals = (object[])args.ReportParameters[0].Value;
- //var settings = ReportConfiguration.GetConfiguration(Regex.Replace(args.Report.Name.Replace(".rdlx",""), @"\d+$", ""));
- var settings = ReportConfiguration.GetConfiguration(vals[1].ToString());
- //内置数据源DataTable
- if (settings != null && "DATASET".Equals(dataSourceType))
- {
- //动态获取数据源服务实例
- var serviceProvider = app.ApplicationServices;
- var reportServiceFactory = serviceProvider.GetService<IReportServiceFactory>();
- var strategy = reportServiceFactory.GetReportService(settings.StrategyType);
- if (strategy != null)
- {
- return strategy.LoadData(args).GetAwaiter().GetResult();
- }
- }
- // TODO:处理不支持的数据源类型
- return null;
- };
- });
- app.UseReportDesigner(config =>
- {
- config.UseFileStore(ResourcesRootDirectory, null, FileStoreOptions.NestedFoldersLookup);
- //config.UseResourcesProvider();
- });
- return app;
- }
复制代码
需要调整哪个位置才能访问报表文件? |