0
votes

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:&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtFromDate" runat="server" TabIndex="1"></asp:TextBox>
    <br />
    txtToDate:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtToDate" runat="server" TabIndex="2"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <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()
2
@MAW74656 could you show us some code pleasemsarchet
Which line throws the error? I suspect it's probably the report.Load.Chris B. Behrens
No error message on these lines of code, the error message is thrown from the Crystal Reports Viewer control trying to print. I did not implement this in code. I was asked for some code, so I posted everything to do with the page, but none of this code seems to be problematic.MAW74656
@Andrew- Your comment should be listed as another answer so I can award you the bounty if your link does the trick. I'll give it a try.MAW74656

2 Answers

0
votes

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.

0
votes

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?