Click here to Skip to main content
15,792,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have been given the task of creating a WCF application hosted as a windows service to accept a Stream of data and then compile this into a file and print the file to a specified printer on our network. Most aspects of this application have now been completed however I am struggling with the printing method. Whenever I try and invoke the method for printer I am given the following error:
{"Settings to access printer '\\\\UKSPPS01\\UKSPPRN024' are not valid."}
I have looked online into this error and the only answers I can find is to have the printer installed locally, however this isn't really a viable option with this service. Has anybody got any better suggestions on how to overcome this, or how to print a file to a network printer not using the System.Drawing method I am using.
The code for printing is simply:
streamToPrint = new StreamReader(filePath);

        printFont = new Font("Arial", 10);
        PrintDocument pd = new PrintDocument();
        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
        pd.PrinterSettings.PrinterName = @"\\UKSPPS01\UKSPPRN024";
        // Print the document.

1 solution

You will need to have a domain account under which the windows service runs in order to access the printer that is available on network.

Check this link[^]
Share this answer
SymbioticKaos 10-Apr-13 3:36am    
Thank you for your post, this is a very good solution and I have tested against my application and it works fine. I also found another solution posted on Stack Overflow which can be found here
Rai Pawan 10-Apr-13 4:58am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900