Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在控制台应用程序中从rdlc创建pdf报告_C#_Reporting Services_Console Application_Rdlc - Fatal编程技术网

C# 在控制台应用程序中从rdlc创建pdf报告

C# 在控制台应用程序中从rdlc创建pdf报告,c#,reporting-services,console-application,rdlc,C#,Reporting Services,Console Application,Rdlc,我想从使用向导创建的rdlc文件生成pdf报告。为此,我尝试编写一个简单的控制台应用程序。当我搜索时,我发现这项任务可以在console/win forms/web apps中完成。我在下面的每一行都遇到了错误 byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); 查看器对象来自Microsoft

我想从使用向导创建的rdlc文件生成pdf报告。为此,我尝试编写一个简单的控制台应用程序。当我搜索时,我发现这项任务可以在console/win forms/web apps中完成。我在下面的每一行都遇到了错误

byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
查看器对象来自Microsoft.Reporting.WinForms。请。帮助我已将此dll文件用于控制台应用程序。下面是完整的
Main()
方法:

        // Setup DataSet
        mybookstoreDataSetTableAdapters.authorsTableAdapter ds = new mybookstoreDataSetTableAdapters.authorsTableAdapter();
        // Create Report DataSource
        ReportDataSource rds = new ReportDataSource("DataSet1", (DataTable)ds.GetData());

        // Variables
        Warning[] warnings;
        string[] streamIds;
        string mimeType = string.Empty;
        string encoding = string.Empty;
        string extension = string.Empty;

        // Setup the report viewer object and get the array of bytes
        ReportViewer viewer = new ReportViewer();                      
        viewer.LocalReport.ReportEmbeddedResource = @"F:\TFS test\ConsoleApplication\ConsoleApplication\Report1.rdlc";
        viewer.ProcessingMode = ProcessingMode.Local;            

        byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

        using (FileStream fs = new FileStream(@"F:\TFS test\ConsoleApplication\ConsoleApplication\Authors.pdf", FileMode.Create))
        {
        fs.Write(bytes, 0, bytes.Length);
        fs.Close();
        }
我还尝试了
viewer.LocalReport.ReportPath
而不是
viewer.LocalReport.ReportEmbeddedResource
viewer.LocalReport.LocalReportDefinition(TextReader)
,将.rdlc文件移动到文件夹.exe resided等

以下是异常的外观:

关于调试->

Microsoft.Reporting.WinForms.LocalProcessingException was unhandled
  HResult=-2146233088
  Message=An error occurred during local report processing.
  Source=Microsoft.ReportViewer.WinForms
  StackTrace:
       at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
       at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
       at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
       at Microsoft.Reporting.WinForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
       at Microsoft.Reporting.WinForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
       at ConsoleApplication.Program.Main(String[] args) in f:\TFS test\ConsoleApplication\ConsoleApplication\Program.cs:line 38
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ApplicationException
       HResult=-2146232832
       Message=The report definition for report 'F:\TFS test\ConsoleApplication\ConsoleApplication\Report1.rdlc' has not been specified
       Source=Microsoft.ReportViewer.Common
       StackTrace:
            at Microsoft.Reporting.PreviewStore.GetCompiledReport(CatalogItemContextBase context, Boolean rebuild, Byte[]& reportDefinition, ControlSnapshot& snapshot)
            at Microsoft.Reporting.PreviewStore.GetCompiledReport(CatalogItemContextBase context, Boolean rebuild, ControlSnapshot& snapshot)
            at Microsoft.Reporting.LocalService.GetCompiledReport(CatalogItemContextBase itemContext, Boolean rebuild, ControlSnapshot& snapshot)
            at Microsoft.Reporting.LocalService.CompileReport(CatalogItemContextBase itemContext, Boolean rebuild)
            at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
       InnerException: 
跑步时->

    Unhandled Exception: Microsoft.Reporting.WinForms.LocalProcessingException: An error occurred during local report processing. ---> System.ApplicationException: The report definition for report 'F:\TFS test\ConsoleApplication\ConsoleApplication\bin\Debug\Report1.rdlc' has not been specified
   at Microsoft.Reporting.PreviewStore.GetCompiledReport(CatalogItemContextBase context, Boolean rebuild, Byte[]& reportDefinition, ControlSnapshot& snapshot)
   at Microsoft.Reporting.LocalService.GetCompiledReport(CatalogItemContextBase itemContext, Boolean rebuild, ControlSnapshot& snapshot)
   at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
   --- End of inner exception stack trace ---
   at Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
   at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
   at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
   at Microsoft.Reporting.WinForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
   at Microsoft.Reporting.WinForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
   at ConsoleApplication.Program.Main(String[] args) in f:\TFS test\ConsoleApplication\ConsoleApplication\Program.cs:line 38
Press any key to continue . . .

请帮助。

不确定这是否能解决您的问题-但我通常使用
viewer.LocalReport.ReportPath=@“F:\TFS test\ConsoleApplication\ConsoleApplication\Report1.rdlc”-我定义了
.ReportPath
(而不是您一直在使用的内容)-您可以试试吗?我还尝试了viewer.LocalReport.ReportPath而不是viewer.LocalReport.ReportEmbeddedResource。