Peter's Gekko

Sponsors

The Lounge

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 01-16-2004 2:04 PM by pvanooijen
Filed under:

[Advertisement]

Comments

Lance wrote re: Once more on Crystal (Access to report file denied)
on 01-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 02-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 03-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 03-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 04-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 04-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 05-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 05-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 05-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 06-07-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 06-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 06-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 07-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 08-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 10-12-2004 4:50 PM
Ping Back??:blog.csdn.net
jonn wrote re: Once more on Crystal (Access to report file denied)
on 10-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 11-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 11-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 02-03-2005 3:13 PM
Crystal blows
Peter van Ooijen wrote re: Once more on Crystal (Access to report file denied)
on 02-03-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 06-06-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 07-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 04-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 12-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 02-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 02-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 01-14-2009 1:01 AM

Evenyouset

Add a Comment

(required)  
(optional)
(required)  
Remember Me?