zhengwei_cq 发表于 2021-9-23 11:27:24

web设计器

本帖最后由 Crystal.Li 于 2021-9-24 14:45 编辑

报表设计器在预览时钻取报表提示“找不到xxx文件”的路径,但是在集成在web网页上可以,我自定义了设计的路径,取配置文件中的路径。
请看我的Startup.cs中的代码:
public class Startup
    {
      public static string EmbeddedReportsPrefix = "WebDesigner_MVC_Core.Reports";
      private static readonly DirectoryInfo ResourcesRootDirectory =
             new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "resources" + Path.DirectorySeparatorChar));

      private static readonly DirectoryInfo TemplatesRootDirectory =
            new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "templates" + Path.DirectorySeparatorChar));
      IConfiguration cfg { get; set; }
      public Startup(IConfiguration _cfg)
      {
            this.cfg = _cfg;
      }

      private static readonly DirectoryInfo DataSetsRootDirectory =
            new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "datasets") + Path.DirectorySeparatorChar);
      // This method gets called by the runtime. Use this method to add services to the container.
      // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
      public void ConfigureServices(IServiceCollection services)
      {
            services
               .AddReporting()
               .AddDesigner()
               .AddSingleton<ITemplatesService>(new FileSystemTemplates(!string.IsNullOrEmpty(cfg["TemplateReportSource"]) ? new DirectoryInfo(Path.Combine(cfg["TemplateReportSource"] + Path.DirectorySeparatorChar)) : new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "resources" + Path.DirectorySeparatorChar))))
               .AddSingleton<IDataSetsService>(new FileSystemDataSets(DataSetsRootDirectory))
               .AddMvc(options => options.EnableEndpointRouting = false)
               .AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
      }

      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseReporting(config => {
                config.UseFileStore(!string.IsNullOrEmpty(cfg["CustomReportSource"]) ? new DirectoryInfo(Path.Combine(cfg["CustomReportSource"] + Path.DirectorySeparatorChar)) : new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "resources" + Path.DirectorySeparatorChar)));
                //config.UseEmbeddedTemplates(EmbeddedReportsPrefix, Assembly.GetAssembly(GetType()));
                //config.UseCompression = true;

            }


            );

            //app.UseReporting(config =>
            //config.UseFileStore(!string.IsNullOrEmpty(cfg["CustomReportSource"]) ? new DirectoryInfo(Path.Combine(cfg["CustomReportSource"] + Path.DirectorySeparatorChar)) : new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "resources" + Path.DirectorySeparatorChar)))
            //);

            app.UseDesigner(config => config.UseFileStore(!string.IsNullOrEmpty(cfg["CustomReportSource"]) ? new DirectoryInfo(Path.Combine(cfg["CustomReportSource"] + Path.DirectorySeparatorChar)) : new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "resources" + Path.DirectorySeparatorChar)), false));

            app.UseStaticFiles();
            app.UseMvc();
      }
    }



配置文件代码:

Crystal.Li 发表于 2021-9-23 11:27:25

您好,这个通过这一段代码看不出,我们这边使用示例工程测试是ok的。一般遇到这种问题,您可以加断点调试一下,看报表路径是否正常。
页: [1]
查看完整版本: web设计器