我有两个项目如下:
首先:所有报告(rdlc文件)都在这里。
第二个: SharePoint 2010 解决方案,显示我的报告。
我使用以下代码访问dll中的 RDLC 文件,并将其放入第二个项目中 SharePoint应用页的reportviewer
控件中:
Assembly assembly = Assembly.LoadFrom("ReportsLib.dll");
Stream stream = assembly.GetManifestResourceStream("ReportsLib.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDefinition(stream);
如果我想从ReportsLib
获取 rdlc 文件(例如:MyReport.rdlc)并将其放入SharePoint应用页面中的reportviewer控件中,则会出现以下错误:
[FileNotFoundException: Could not load file or assembly 'file:///c:\windows\system32\inetsrv\ReportsLib.dll' or one of its dependencies. The system cannot find the file specified.]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
System.Reflection.Assembly.LoadFrom(String assemblyFile) +52
HRS.ReportsViewer.Layouts.ShowReport.Page_Load(Object sender, EventArgs e) +77
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase.OnLoad(EventArgs e) +101
Microsoft.SharePoint.WebControls.LayoutsPageBase.OnLoad(EventArgs e) +49
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
我做错了什么?
答案 0 :(得分:1)
程序集名称似乎是ReportsLib
,假设您已使用默认名称空间,则需要进行如此调整:
var assembly = Assembly.LoadFrom("ReportsLib.dll");
var stream = assembly.GetManifestResourceStream("ReportsLib.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDefinition(stream);
此外,如果您将MyReport.rdlc
移到文件夹中,那么您还需要添加一个虚线文件夹路径,即
GetManifestResourceStream("ReportsLib.SomeFolder.MyReport.rdlc");
编辑如果程序集已经过GAC编辑,请尝试提供完全限定的程序集名称,例如
var assembly = Assembly.LoadFrom("ReportsLib.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxx");
您可以使用以下方法之一获取FQN: How do I find the fully qualified name of an assembly?