PrintPropertyDictionary.SetProperty Method (String, PrintProperty)


Sets the value of the specified attribute to an object of a class that is derived from PrintProperty.

Namespace:   System.Printing.IndexedProperties
Assembly:  System.Printing (in System.Printing.dll)

public void SetProperty(
	string attribName,
	PrintProperty attribValue


Type: System.String

The name of the attribute.

Type: System.Printing.IndexedProperties.PrintProperty

An object of a type that is derived from PrintProperty.

Exception Condition

attribName is already in the dictionary and it already has the value attribValue.

If the dictionary does not already contain attribName, attribName will be added and set to attribValue, provided that attribName is identical to attribValue.Name. If these values are not identical, this method does nothing.

The following example shows how to use this method to install a second printer that differs in its properties from an existing printer only in location, port, and shared status.

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

// Share the new printer using Remove/Add methods
PrintBooleanProperty shared = new PrintBooleanProperty("IsShared", true);
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.Add("Location", theLocation);

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

// Install the new printer on the local print server
PrintQueue clonedPrinter = myLocalPrintServer.InstallPrintQueue("My clone of " + sourcePrintQueue.Name, "Xerox WCP 35 PS", port, "WinPrint", myPrintProperties);

// Report outcome
Console.WriteLine("{0} in {1} has been installed and shared as {2}", clonedPrinter.Name, clonedPrinter.Location, clonedPrinter.ShareName);
Console.WriteLine("Press Return to continue ...");

.NET Framework
Available since 3.0
Return to top