Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WCF printing
Hi,
 
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);
                try
                {
 
                        printFont = new Font("Arial", 10);
                        PrintDocument pd = new PrintDocument();
                        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                        pd.PrinterSettings.PrinterName = @"\\UKSPPS01\UKSPPRN024";
                        // Print the document.
                        pd.Print();
                }
                finally
                {
                    streamToPrint.Close();
                }
Posted 8-Apr-13 23:58pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 http://stackoverflow.com/questions/8009558/printing-in-windows-service-using-background-worker[^]
  Permalink  
Comments
SymbioticKaos at 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 http://stackoverflow.com/questions/2722327/error-settings-to-access-printer-printername-are-not-valid-when-printing-fro
Rai Pawan at 10-Apr-13 4:58am
   
welcome
-pawan

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 746
1 OriginalGriff 345
2 Magic Wonder 131
3 Kishore Pogaru 130
4 Fredrik Bornander 130
0 OriginalGriff 5,705
1 Sergey Alexandrovich Kryukov 4,763
2 CPallini 4,570
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100