I'm using the .net Crystal Reports viewer to display a report in an asp.net Web form. This works properly, but when I click on the print option, and then click "OK" on the options popup, I get the following error:
Access is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Runtime.InteropServices.COMException: Access is denied.
And the same thing when I try to export. I'm running this on the Visual Studio development server, VS2008. What can I do to correct this?
EDIT:
Here is some code.
txtCategory:
<asp:TextBox ID="txtCategory" runat="server"></asp:TextBox>
<br />
txtFromDate:
<asp:TextBox ID="txtFromDate" runat="server" TabIndex="1"></asp:Tex开发者_如何学运维tBox>
<br />
txtToDate:
<asp:TextBox ID="txtToDate" runat="server" TabIndex="2"></asp:TextBox>
<asp:Button ID="btnShowReport" runat="server" onclick="btnShowReport_Click"
TabIndex="4" Text="Show Report" />
<br />
<br />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
</CR:CrystalReportSource>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="True" DisplayGroupTree="False" EnableDatabaseLogonPrompt="False"
EnableParameterPrompt="False" HasRefreshButton="True" Height="50px"
ReportSourceID="CrystalReportSource1" Width="350px" />
And in Code-Behind:
protected void btnShowReport_Click(object sender, EventArgs e)
{
ReportDocument report = new ReportDocument();
report.Load(Server.MapPath(@"~\ReportFiles\CrystalReport.rpt"));
report.SetParameterValue("value1", txtCategory.Text);
ParameterRangeValue dateRange = new ParameterRangeValue();
CrystalReportViewer1.ReportSource = report;
}
STACKTRACE: at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
I don't know the exact answer to your question but I can suggest what I would look at which I hope helps. As it's an access denied error I would look at the access rights to where this ends up:
Server.MapPath(@"~\ReportFiles\CrystalReport.rpt")
A Google search for CrystalDecisions.ReportAppServer access denied suggested that you can use impersonate in the web.config to access that folder with a user that has read/write access.
<authentication mode="Windows" />
<identity impersonate="true" userName="domainname\username" password="mypassword" />
Using Windows authentication would presumably ensure the impersonation is used.
Hope that helps.
Well, I've discovered 2 things:
1) My Visual Studio started throwing errors when I opened it, forcing me to search the ends of the internet and use devenv /resetuserdata to reset the environment. That fixed part of it. I also repaired my .NET installations, but I don't know if that did anything.
2) Apparently I needed to refresh the reportviewer after assigning the report to the viewer in my code.
I added this:
CrystalReportViewer1.RefreshReport();
To the bottom of my code, and viola! Now I can export and print. How simple and nuts is that?
精彩评论