2017-03-16 46 views
-1

處理Table'table2'時發生錯誤:程序集「AssemblyName.Context,Version = 1.0.0.0,Culture = neutral ,PublicKeyToken = null「不允許被ObjectDataSource組件使用。請將其包含在應用程序配置文件的Telerik.Reporting配置部分中的AssemblyReferences元素中。爲什麼從C#導出Telerik報表時,組件不允許被ObjectDataSource組件使用該組件#

我正在使用下面的代碼導出PDF報告。

public static System.IO.Stream GerRep(List<EquipmentSearchResult> list) 
     { 
      EquipmentExportReportT report = new EquipmentExportReportT(); 

      report.ReportParameters["BaseLocationName"].Value = "MyTest"; 
      //report.DataSource = list; 

      ReportProcessor reportProcessor = new ReportProcessor(); 

      // set any deviceInfo settings if necessary 
      System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable(); 

      Telerik.Reporting.TypeReportSource typeReportSource = new Telerik.Reporting.TypeReportSource(); 

      // reportName is the Assembly Qualified Name of the report 
      typeReportSource.TypeName = typeof(EquipmentExportReportT).AssemblyQualifiedName; 

      RenderingResult result = reportProcessor.RenderReport("XLS", typeReportSource, deviceInfo); 

      string fileName = result.DocumentName + "." + result.Extension; 
      string path = System.IO.Path.GetTempPath(); 
      string filePath = System.IO.Path.Combine(path, fileName); 

      using (FileStream fs = new FileStream(filePath, System.IO.FileMode.Create)) 
      { 
       fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length); 
      } 

      MemoryStream ms = new MemoryStream(result.DocumentBytes); 
      ms.Position = 0; 

      return ms; 
     } 

回答

2

這是配置問題,您需要在web.config文件上應用一些設置。

在這種情況下,應用程序配置文件需要被修改並需要在一個新的節點以下面的方式加入的AssemblyReferences元件內容中的組件的名稱:

<configuration> 

    <configSections> 
    <section name="Telerik.Reporting" type="Telerik.Reporting.Configuration.ReportingConfigurationSection, Telerik.Reporting" allowLocation="true" allowDefinition="Everywhere" /> 
    </configSections> 

    <Telerik.Reporting> 
    <assemblyReferences> 
     <add name="yourAssemblyName"/> 
    </assemblyReferences> 
    </Telerik.Reporting> 

</configuration> 

我希望這將解決你的問題。歡呼:)

+0

是的,它的工作,thansk –

+0

..................................... ........ :) –

+0

謝謝...... :) –

相關問題