.NET 3.0 System.Printing

  • Thread starter Thread starter torsti181279
  • Start date Start date
T

torsti181279

Hi there,

i try to clone a printer .. just as it was posted at
http://msdn2.microsoft.com/en-us/library/aa970846.aspx
"How to: Clone a Printer"

but i got problems when setting PrintQueueAttributes ... is there
anyone who can show me the way getting
from PrintPropertyDictionary to PrintQueueAttributes (btw. casting
does not work :-) ) or to show me how to Set the
PrintQueueAttributes ...

below you´ll find the script taken from ms-website...
when starting this i´m getting an InvalidCastException at the
"myPrintProperties" (type:PrintPropertyDictionary ) parm...

Exception:
System.InvalidCastException: Das Objekt des Typs
System.Printing.PrintQueueAttributes kann nicht in Typ System.Int32
umgewandelt werden.
Code:
clonedPrinter = myLocalPrintServer.InstallPrintQueue(printQuename,
printDriver, pport, printPrcessorName, myPrintProperties);


thanks alot....
torben

-------snip--------

LocalPrintServer myLocalPrintServer = new
LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintPrintServer(myLocalPrintServer, rtb);
PrintQueue sourcePrintQueue = myLocalPrintServer.DefaultPrintQueue;
PrintPropertyDictionary myPrintProperties =
sourcePrintQueue.PropertiesCollection;

// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared",
true);
myPrintProperties.Remove("IsShared");
myPrintProperties.Add("IsShared", shared);

// Give the new printer its share name using SetProperty method
PrintStringProperty theShareName = new
PrintStringProperty("ShareName", "\"Son of " + sourcePrintQueue.Name +
"\"");
myPrintProperties.SetProperty("ShareName", theShareName);

// Specify the physical location of the new printer using Remove/Add
methods
PrintStringProperty theLocation = new PrintStringProperty("Location",
"the supply room");
myPrintProperties.Remove("Location");
myPrintProperties.Add("Location", theLocation);

// Specify the port for the new printer
String[] port = new String[] { "COM1:" };

// Install the new printer on the local print server
string printQuename = "Torsten Virtual Printer Copy";
string printDriver = sourcePrintQueue.QueueDriver.Name;
PrintString(printDriver, rtb);
string printPrcessorName =
sourcePrintQueue.QueuePrintProcessor.ToString();
PrintString(printPrcessorName, rtb);
string[] pport = new string[] { sourcePrintQueue.QueuePort.Name };
PrintString(sourcePrintQueue.QueuePort.Name, rtb);

clonedPrinter = myLocalPrintServer.InstallPrintQueue(printQuename,
printDriver, pport, printPrcessorName, myPrintProperties);

myLocalPrintServer.Commit();

----------snap------------
 
that is the complete exception ...

System.InvalidCastException: Das Objekt des Typs
System.Printing.PrintQueueAttributes kann nicht in Typ System.Int32
umgewandelt werden.
bei
MS.Internal.PrintWin32Thunk.DirectInteropForPrintQueue.PrinterInfoTwoSetter.SetAttributes(IntPtr printerInfoTwoBuffer, Object value)
bei
MS.Internal.PrintWin32Thunk.DirectInteropForPrintQueue.PrinterInfoTwoSetter.SetValueFromName(String valueName, Object value)
bei System.Printing.PrintQueue.Install(PrintServer printServer, String
printQueueName, String driverName, String[] portNames, String
printProcessorName, PrintPropertyDictionary initializationParams)
bei System.Printing.PrintServer.InstallPrintQueue(String printQueueName,
String driverName, String[] portNames, String printProcessorName,
PrintPropertyDictionary initialParameters)
 
Problem solved..there was an uninitialized property..

Getting all possible properties :

PrintPropertyDictionary printQueueProperties =
defaultPrintQueue.PropertiesCollection;

PrintString(String.Format("These are the properties, and their types, of
{0}, a {1}", defaultPrintQueue.Name, defaultPrintQueue.GetType().ToString() +
"\n"), rtb);

foreach (DictionaryEntry entry in printQueueProperties)
{
PrintProperty property = (PrintProperty)entry.Value;

if (property.Value != null)
{
PrintString(String.Format(property.Name + "\t(Type: {0})",
property.Value.GetType().ToString()), rtb);
}
}
 
Back
Top