Print SSRS Reports directly to a printer

  • I'm using Visual Studio 2005 and SQL Server 2005 on a Windows Server 2003 operating system.  I'm trying to print Reporting Services Reports dirctly to the printer without using the Report Manager to preview.  I'm using some VB.NET code that I found at the following location:

    http://www.codeproject.com/vb/net/RSPrintLandscape.asp

      I have an ASP.NET application that I'm running on a local maching to locate and print reports from a remote report server on another on another machine.  The application downloads a report in PDF format and creates a file on my local machine successfully, but when I try to write to the file I get the following error:

    ***********************************************************************

    Server Error in '/Reporter2' Application.

     

    Access to the path 'C:\PRINT_TEMP.PDF' 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.UnauthorizedAccessException: Access to the path 'C:\PRINT_TEMP.PDF' is denied.

    ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

    To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

    Source Error:

    Line 256: WebFile.Credentials = CredentialCache.DefaultCredentials

    Line 257: 'Create the local file

    Line 258: LocalFile = New FileStream(DestFilename, FileMode.Create)

    Line 259:

    Line 260: 'Download the file in 16k chunks

    Source File: C:\Projects\ICISMainReport2\PrintDirect.aspx.vb Line: 258

    Stack Trace:

    [UnauthorizedAccessException: Access to the path 'C:\PRINT_TEMP.PDF' is denied.]

    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +2013027

    System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +998

    System.IO.FileStream..ctor(String path, FileMode mode) +65

    PrintDirect._PrintDirect.DownloadWebFile(String URL, String DestFilename) in C:\Projects\ICISMainReport2\PrintDirect.aspx.vb:258

    PrintDirect._PrintDirect.btnPrint_Click(Object sender, EventArgs e) in C:\Projects\ICISMainReport2\PrintDirect.aspx.vb:207

    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105

    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107

    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7

    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11

    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33

    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

    ******************************************************************************

    I considered the suggestion that was listed with the error message but please note that this file is created on the user's machine each time the application is run.  How can I control permissions for a file on each user's machine?

    Any suggestion how I might overcome this problem?

    Thanks

    RickyZX

  • There are basically two ways to do what you want to do:

    1) control the position of the temporary file (use System.IO.Path.GetTempPath() or whatever to find someplace you can expect access to). BTW I'm thinking you're going to want to erase the file after the print, so it makes sense to me that you should know exactly where it is and what it is called.  Is this the case or not?

    2) control the personae/credentials under which the ASP.NET application runs.  This is often an appropriate thing to do for ASP.NET applications (or any web server applications) that have to access local file systems.  In your case I'm a little confused about how you plan to run this in production.  You say that it's an ASP.NET application (ie web server hosted) but it's going to be creating local files on each user's machine? You may want to back up a bit and discuss architecture.  We can take this off-line (since this is not SQL Server territory and has nothing to do with SSRS necesarily) if you like.

    >L<

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply