This documentation is archived and is not being maintained.

HtmlDocument.Images Property

Gets a collection of all image tags in the document.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public HtmlElementCollection Images { get; }

Property Value

Type: System.Windows.Forms.HtmlElementCollection
A collection of HtmlElement objects, one for each IMG tag in the document. Elements are returned from the collection in source order.

Images returns a collection of HtmlElement objects. To access attributes, such as ALT and SRC, that are not directly exposed by HtmlElement, use the GetAttribute method.

To add a new image to a document, either create a new IMG tag as a string, and assign it to the InnerHtml property of an element previously added to the HTML DOM; or use the CreateElement method, set its properties using SetAttribute, and add it as a child of an existing element using AppendChild.

The following code example examines the ALT attribute of all of the images in the document, and sets a default ALT attribute if a value is not already set.

private string[] GetImageUrls()
    if (webBrowser1.Document != null)
        HtmlDocument doc = webBrowser1.Document;
        string[] urls = (string[])Array.CreateInstance(Type.GetType("System.String"), doc.Images.Count);

        foreach (HtmlElement imgElement in doc.Images)
            urls[urls.Length] = imgElement.GetAttribute("src");
        return (urls);
        return (new string[0]);

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0