Reputation: 31
I am out of idea why this is NOT working:
PrintServer printServer = new PrintServer("\\\\servername");
I am having issue with the PrintServer initialization. The above mentioned exception keep appearing even the printerServer path provided is a valid path. This is being said so as I am able to enumerate all the printers using printerServer.GetPrintQueues and foreach the printQueue to get the corresponding HostingPrintServer name.
EnumeratedPrintQueueTypes[] queueTypesArray = new EnumeratedPrintQueueTypes[]
{
EnumeratedPrintQueueTypes.Connections,
EnumeratedPrintQueueTypes.Local,
};
PrintQueueIndexedProperty[] indexPropertyArray = new PrintQueueIndexedProperty[]
{
PrintQueueIndexedProperty.Name
};
PrintServer printServer = new PrintServer();
PrintQueueCollection queueCollection = printServer.GetPrintQueues(indexPropertyArray, queueTypesArray);
foreach (PrintQueue pq in queueCollection)
{
if (pq.FullName == printerName)
{
this.printServerName = pq.HostingPrintServer.Name;
this.printerName = pq.Name;
}
}
I have also tried using the way this post suggested to get the DNS hostEntry but without any luck.
PrintServerException - "...name is invalid" even though I can access the path from windows
For your information, I am using Visual Studio 2010 running on Windows XP with two network printers connected. The printers are able to perform printing without any issue using PrintDocument and the printers are displayed on the PrintDialog as well.
Does anyone faced this issue before? If yes, may I know how do you resolve the issue?
Million thanks in advance.
EDIT:
Just tested with another "real" server printer, the above mentioned method is working fine. It is believed that Novell iPrint service which I am not sure how is the behaviour of it causing the issue. If anyone know more about the way to access Novell iPrint print server using C#, please feel free to share. I am currently still searching for the solution.
Upvotes: 3
Views: 6356
Reputation: 429
hey i was facing similar issue, this is what i observed and made following changes, just try and let me know.
This issue was occuring due to windows feature/role "Print and Document service" is missing on the system. This role is required for managing multiple printers or print servers and migrating printers to and from other windows servers.
To add the role Go To Control Panel->Turn windows feature on or off->click on check box "Print and Document Service"->install.
See with network administrator for installing this rule if you unable to add it.
After adding the role you can able to create print server object and get the all the printqueues on respective server.
Upvotes: 3