Microsoft KB Archive/821623

= Help topic for PropertyItem class is not complete =

Article ID: 821623

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





SUMMARY
In the Microsoft .NET Framework Class Library documentation, the help topic for the PropertyItem class is not complete.

For more information, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/system.drawing.imaging.propertyitem(vs.71).aspx



MORE INFORMATION
The existing documentation states the following:

Encapsulates a metadata property to be included in an image file. Not inheritable.

The documentation should also state the following:

A PropertyItem is not intended to be used as a stand-alone object. A PropertyItem object is intended to be used by classes that are derived from System.Drawing.Image. A PropertyItem object is used to retrieve and to change the metadata of existing image files, not to create the metadata. Therefore, the PropertyItem class does not have a defined Public constructor, and you cannot create an instance of a PropertyItem object.

To work around the missing Public constructor, use an existing PropertyItem object instead of creating a new instance of the PropertyItem class. To do this, use the following sample code:

Visual Basic .NET sample code
' Create an Image to gain access to an existing PropertyItem object from. Dim MyImage As System.Drawing.Image = Image.FromFile(&quot;C:\Sample.jpg&quot;) ' Refer to some existing .JPEG image.

' Define a PropertyItem variable. Dim pItem As System.Drawing.Imaging.PropertyItem

' Instead of creating a new instance of PropertyItem, use an existing PropertyItem object. For Each pItem In MyImage.PropertyItems ' Obtain a reference to the first PropertyItem object of MyImage, and then exit the loop. Exit For Next

' You may modify and use the pItem object now.

Visual C# .NET sample code
// Create an Image to gain access to an existing PropertyItem object from. System.Drawing.Image MyImage = Image.FromFile(&quot;C:\\Sample.jpg&quot;); // Refer to some existing .JPEG image.

// Instead of creating a new instance of PropertyItem, use an existing PropertyItem object. foreach (System.Drawing.Imaging.PropertyItem pItem in MyImage.PropertyItems) {  // Obtain a reference to the first PropertyItem object of MyImage, and then exit the loop. break; }

// You may modify and use the pItem object now. Note For this code to work correctly, you must have a reference to the System.Drawing.dll assembly.

