Peter's Gekko

Sponsors

The Lounge

Wicked Cool Jobs

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Once more on Crystal (Access to report file denied)

I still do like Crystal reports but getting them to work on a production machine can be pretty frustrating. Responses to earlier posts showed me that I'm not the only one. So here's another.

You can print a Crystal report on a webpage by exporting it as a PDF or a Word doc. The browser will catch this in a viewer from where you do the real printing. There is a sample on the Crystal website which I followed quite sheepishly. It worked on my machine but the production machine showed a quite interesting error

C:\DOCUME~1\S01NT0~1\ASPNET\LOCALS~1\Temp\temp_b8805d74-11f7-4721-b614-88b564c0b8a4.rpt: Access to report file denied. Another program may be using it.

There is indeed an access problem, but not with the report file. Browsing the web I found the solution on the Crystal site. This led me to do some refactoring on the example which resulted in a helper method I would like to share with you:

protected void exportReport(CrystalDecisions.CrystalReports.Engine.ReportClass selectedReport, CrystalDecisions.Shared.ExportFormatType eft)
{

string contentType ="";
// Make sure asp.net has create and delete permissions in the directory
string tempFileName = System.Configuration.ConfigurationSettings.AppSettings["TempDir"] + Session.SessionID.ToString() + ".";

switch (eft)
{
case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat :
tempFileName += "pdf";
contentType = "application/pdf";
break;

case CrystalDecisions.Shared.ExportFormatType.WordForWindows :
tempFileName+= "doc";
contentType = "application/msword";
break;

}

CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions();
dfo.DiskFileName = tempFileName;

CrystalDecisions.Shared.ExportOptions eo = selectedReport.ExportOptions;
eo.DestinationOptions = dfo;
eo.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
eo.ExportFormatType = eft;

selectedReport.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = contentType;

Response.WriteFile(tempFileName);
Response.Flush();
Response.Close();

System.IO.File.Delete(tempFileName);

}

You pass the method the report and the desired format in the parameters. The code is pretty straightforward. The essential thing is that you have to create a temporary file for the result. To create this file your app needs some rights. To make sure the app will have the rights we added an entry in the web.config and the code will read this using the AppSettings property. System management can now assign a scratch dir

Part of web.config

<appSettings>
<add key="TempDir" value
="c:\temp\">add>

And this does work.

Blog on, Peter

<appSettings>
<add key="TempDir" value
="c:\temp\">add>

And this does work.

Blog on, Peter


Posted Fri, Jan 16 2004 2:04 PM by pvanooijen
Filed under:

[Advertisement]

Comments

Lance wrote re: Once more on Crystal (Access to report file denied)
on Sat, Jan 17 2004 9:11 PM
You should check-out Microsoft's new product "Sql Reporting Services" if you do alot of reports and want an alternative to Crystal.

http://www.microsoft.com/sql/reporting/

This is Microsoft's answer to the Crystal Enterprise reporting server. It supports multiple rendering formats (PDF, HTML, Excel, Word, XML, etc.) and offers a web-service based interface for generating or administering the reports.

The best part is that its free if you are using Sql Server 2000. (eg. can setup 1 instance per Sql Server 2k license)

Of course, since this is a server-based solution, it might be a bit overkill for an app that needs only one or two reports total.
Peter's Gekko wrote Exporting from Crystal Reports to PDF, Word, Excel and HTML
on Tue, Feb 10 2004 8:36 PM
Exporting from Crystal Reports to PDF, Word, Excel and HTML
Madhusudanan wrote re: Once more on Crystal (Access to report file denied)
on Thu, Mar 25 2004 6:02 AM
Hi
Go to c:\inetpub\wwwroot .There write click and selct properties.Make sure for VS application u provide full control.Else do the same.It will work

Madhu
Peter van Ooijen wrote re: Once more on Crystal (Access to report file denied)
on Thu, Mar 25 2004 6:21 AM
Sorry but that sounds like a bad, unsecure idea. Very few sa's will do this for you. My idea is to give the app a safe isoloated scratchpad.
John wrote Need help!
on Mon, Apr 19 2004 10:16 AM
if I have a report named "Employee.rpt", what do I pass in for the function protected void exportReport(CrystalDecisions.CrystalReports.Engine.ReportClass selectedReport, CrystalDecisions.Shared.ExportFormatType eft) ? I don't know what selectedReport supposed to be. Please Help!!!
Peter van Ooijen wrote re: Once more on Crystal (Access to report file denied)
on Mon, Apr 19 2004 10:36 AM
Selectedreport is a (typed) reportdocument on the webform. You'll find the componenet on the components tab of the toolbox.
Emmanuel Lambert wrote re: Once more on Crystal (Access to report file denied)
on Fri, May 14 2004 6:47 AM
had the same problem; setting access rights to the \inetpub\wwwroot\"appname" directory solved the problem indeed...
Peter van Ooijen wrote re: Once more on Crystal (Access to report file denied)
on Fri, May 14 2004 9:58 AM
Changing the rights works without a doubt, but I still find it a bad idea to set the rights in your app dir to delete just because Crystal needs a scratchpad. I beleive it to be a much safer idea to give Crystal a scratch dir where no harm can be done.
Sekar wrote re: Once more on Crystal (Access to report file denied)
on Sat, May 29 2004 7:41 AM
Hi

It is pool problem, It is not allowing to access multi users at the same time , so Proceed as below

server 2003
---------------
inetmgr > ProjectName(exg prjtest)> properties > virtual Directory > Application pool property as MSSharedPool.

Others
--------
inetmgr > ProjectName(exg prjtest)> properties > virtual Directory > Application Protection > Application protection to high isolated

sekar p
psekar79@yahoo.com
(Kasbah Systems Software)
Jabbar wrote re: Once more on Crystal (Access to report file denied)
on Mon, Jun 7 2004 5:41 AM
Hello sekar,
I am a Asp.net programmer I am facing one problem in reporting I want the crystal report to print immediately after i export it to ms-word Can you help me
dancy wrote is it possible to export one report to multiple PDF files ?
on Wed, Jun 16 2004 9:31 PM
In Crystal Reports (CR), is it possible to export separate groups within a report to separate PDF files?

For instance, you have a report grouped on the Country field. You want to export the USA group to one PDF file and the France group to another PDF file
Peter van Ooijen wrote re: Once more on Crystal (Access to report file denied)
on Thu, Jun 17 2004 1:49 AM
What about two passes ? Pass one with a selction for the US, pass two for one for France.
Chris wrote re: Once more on Crystal (Access to report file denied)
on Mon, Jul 26 2004 12:39 PM
I have a report that needs to be created, but the query is too large for CR to handle since I am getting Server Application Unavailable errors most of the time. I am trying to loop through to create multiple documents using the same query, but changes to the WHERE clause each iteration, but I cannot determine how to export it to pdf and then start the loop again for the next file. Any suggestions? Thanks ahead, much appreciated.
Kavitha wrote re: Once more on Crystal (Access to report file denied)
on Wed, Aug 18 2004 9:59 PM
Thanks sekar.
" server 2003 --
inetmgr > ProjectName(exg prjtest)> properties > virtual Directory > Application pool property as MSSharedPool. "

Thanks for your solution. I have changed to Application pool property as MSSharedPool . Now It is working perfectly. Now I am able to export to pdf.

martin wrote Exporting from Crystal Reports to PDF, Word, Excel and HTML
on Tue, Oct 12 2004 4:50 PM
Ping Back??:blog.csdn.net
jonn wrote re: Once more on Crystal (Access to report file denied)
on Tue, Oct 19 2004 4:16 PM
MSSharedPool - What are the properties for that application pool?

It doesn't show up in my app pool list.
Kaya wrote re: Once more on Crystal (Access to report file denied)
on Fri, Nov 19 2004 9:43 AM
because "MSSharedPool" identity is "Local System" it has read/write access to inetpub/wwwroot directory. i think it's like same solution as Madhusudanan answer

"
Go to c:\inetpub\wwwroot .There write click and selct properties.Make sure for VS application u provide full control.Else do the same.It will work"
Peter van Ooijen wrote re: Once more on Crystal (Access to report file denied)
on Fri, Nov 19 2004 11:14 AM
It will work. But is a bad idea. Security matters ! Please do use a dedicated scratch directory ! As my post tries to explain it's no big deal.
Billy Bob wrote re: Once more on Crystal (Access to report file denied)
on Thu, Feb 3 2005 3:13 PM
Crystal blows
Peter van Ooijen wrote re: Once more on Crystal (Access to report file denied)
on Thu, Feb 3 2005 5:49 PM
I am exploring SQL reporting services. Looks good enough to do the job. And its comes royalty free with sql server. Quite a difference to Crystal server fees.
Mohan wrote re: Once more on Crystal (Access to report file denied)
on Mon, Jun 6 2005 8:53 AM
I dont see a MSShared pool. All i see is the default application pool
Ricardo Puente wrote re: Once more on Crystal (Access to report file denied)
on Thu, Jul 14 2005 8:04 AM
Peter it works! thanks for you help.

RP
Ranjith wrote re: Once more on Crystal (Access to report file denied)
on Fri, Apr 27 2007 1:31 AM

How can we set Summary information to files (excel,pdf,doc) on files generated by Crystal report

Sadiq, India wrote re: Once more on Crystal (Access to report file denied)
on Tue, Dec 18 2007 4:29 AM

Thanks for the code. It worked for me :-))

Hendra wrote re: Once more on Crystal (Access to report file denied)
on Mon, Feb 11 2008 10:27 PM

Thanks Sekar, this step works with me :

server 2003

---------------

inetmgr > ProjectName(exg prjtest)> properties > virtual Directory > Application pool property as MSSharedPool.

Due to security issue, anyone know, another way out to solve this problem ?

Peter said 'Please do use a dedicated scratch directory ! ' can u please give an example ?

Thank you.

pvanooijen wrote re: Once more on Crystal (Access to report file denied)
on Fri, Feb 15 2008 3:01 AM

A dedictaed scratch directory ?

Create a folder somewhere on your web server, and give the asp.net worker process write rights there. What's unclear ?

Tony Zhou wrote Crystal Report Error
on Wed, Jan 14 2009 1:01 AM

Evenyouset

B. wrote re: Once more on Crystal (Access to report file denied)
on Thu, Oct 1 2009 12:27 AM

change permissions on c:/windows/temp at the server

give modify right  to user who is set on the application pool , ex NETWORK SERVICE (default for anonymous )

Kooper wrote re: Once more on Crystal (Access to report file denied)
on Thu, Mar 18 2010 11:24 AM

Eliminate the IT reporting bottleneck - Stonefield Query is designed to put Business Intelligence reporting into hands of the end user where it belongs. Stonefield Query Self-service BI reporting solution allows your executive, manager/staff, and business anylists to take advantage of the wealth of information stored in your database system when they need it. Casual users can create elegant and persuasive reports in minutes with little or no technical knowledge.

Visit our website to download a 30 day trial.

www.stonefieldquery.com

pvanooijen wrote re: Once more on Crystal (Access to report file denied)
on Thu, Mar 18 2010 11:40 AM

This is a commercial. I'm not going to delete it but IMHO tools like that are no good at all. Perhaps they have a far better UI than Crystal RS or whatever.

But the majority of the end users don't understand the structure of a database. An object model comes closer to the users view but it takes an O-R mapper to map that to a database and a domain expert to translate it to the end user.

And a well designed report to give the end user the (correct) information he needs.

Tools like this set the expectations of management higher than the reality of the end user.

To say it rude: There is no rocker science for the mentally disabled.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us