Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

System.Printing .NET3.0   (How to set PrintQueueAttributes )

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
torben - 26 Jul 2007 10:48 GMT
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.

>> THERE IS NO PrintQueueAttributes  !! its PrintPropertyDictionary

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------------
torben - 26 Jul 2007 11:18 GMT
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)
torben - 26 Jul 2007 11:40 GMT
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);
                    }
                }

> that is the complete exception ...
>
[quoted text clipped - 11 lines]
> String driverName, String[] portNames, String printProcessorName,
> PrintPropertyDictionary initialParameters)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.