Click here to Skip to main content
12,398,000 members (46,611 online)
Rate this:
 
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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2016
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