views:

162

answers:

1

Trying to print an ASP.NET Charting control behind the scenes in my web app. I think it is a permissions issue with the printer as everything is ok up until the point where my code calls:

chart.Printing.Print(false);
bool finished = false;
while (!finished)
{
    finished = File.Exists(settings.GetValue("statusfile")); // file which indicates document was printed
    System.Threading.Thread.Sleep(1000);
}

At this point the page just freezes (or continues to load endlessly - infinite loop!) Understandably this is happening because I am 100% relying on the document being printed. I do intend to add a timeout, however, at the moment I am just trying to figure out why exactly the document is never being set to the printer!

I have given the account (which the AppPool is running under) permissions to all the relevant folders and even the pdf printer itself...Still nothing.

Am I missing something? Is there any issues with printing on the server side via ASP.NET? I have encountered some issues doing this via WindowsServices in the past not sure if it is a similar problem with ASP.NET websites.

Update

As suggested I updated the AppPool to give myself (admin) permissions and it is the same issue. So by the looks of things the job is never being sent to the printer. I can't seem to figure out why though...

Probably should have mentioned this in my original post....but I am invoking the printer through a referenced DLL, this code is not being called directly from my application (incase it matters). Also this runs fine on my Development machine which is running Windows 7 IIS7.0 where as the server is running Windows 2003 server with IIS6.0.

Update 2

I removed the while loop and just left in the chart.Printing.Print(false) line and turns out the document IS being sent to the printer. So the issue must be with the settings file not getting written which is why the loop never breaks out!

A: 

To isolate if this is indeed a permissions issue, you could try running the application using the Visual Studio web development server, which will run under your credentials. Or if that's not an option, temporarily change the IIS app pool so it uses your credentials. If things still do not work, you may have another issue. I'm not sure which charting library you're using (is it the newish Microsoft one?), but maybe Print wants to show a printer dialog.

Jacob
@Jacob no the `Print` method takes in a parameter to say whether or not you want the dialog to display. I am passing in false. Yes it is the ASP.NET Charting control.
James
As per my update I changed the permissions of the app pool and still getting the same result. Basically the document is never being sent to the printer. Can't seem to figure out why though.
James
Is there a default printer set for the user(s) on the server?
Jacob
@Jacob yes it is always set to the printer I am trying to print to. Also I set the default printer at runtime aswell so it is definetly getting the correct one. Also I run this on my Dev machine and it works fine (which is Windows 7 x64) however as soon as I publish it to Win 2k3 it fails.
James
Turns out the document is getting sent to the printer, it seems like the settings file is never being written to file. Need to investigate this further.
James