This documentation is archived and is not being maintained.

AdRotator.AdvertisementFile Property

Gets or sets the path to an XML file that contains advertisement information.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public string AdvertisementFile { get; set; }
/** @property */
public String get_AdvertisementFile ()

/** @property */
public void set_AdvertisementFile (String value)

public function get AdvertisementFile () : String

public function set AdvertisementFile (value : String)

Property Value

The location of an XML file containing advertisement information. The default value is an empty string ("").

Use the AdvertisementFile property to specify the location of an XML file that contains advertisement information. The XML file must reside within the same Web site. For deployment and security purposes, it is strongly recommended that you place the file in the same Web application. It is only possible to access an XML file that is located in a different application on the same site if the application has sufficient trust.

You can set this property to either an absolute path or a path relative to the XML file. Use a relative path to simplify deployment. If you use a relative path, that path is relative to the location of the page or user control that contains the AdRotator control.

The AdvertisementFile property is optional. An advertisement can also be programmatically set in the AdCreated event.

The XML file contains the following predefined attributes. Only the ImageUrl attribute is required.




The URL of the image to display.


The height of the image, in pixels (optional).


The width of the image, in pixels (optional).


The URL of the page to navigate to when the AdRotator control is clicked.


The text to display if the image is unavailable. On some browsers, this text is displayed as a ToolTip.


The category for the advertisement. This is used by the AdRotator control to filter the list of advertisements for a specific category.


A value that indicates how often an advertisement is displayed in relation to other advertisements in the XML file.


The ImageUrl and NavigateUrl attributes can be a full URL, a root-relative path, or a relative path. If you use a root-relative path, the path is relative to the same Web site. If you use a relative path, the path is relative to the directory that contains the advertisement file.

You can also include custom attributes by using custom tags in the XML file. All attribute tags are parsed from the advertisement file, and the values are placed in the AdProperties dictionary. You can use the AdProperties dictionary to programmatically access your custom attributes.

Information in this file is not validated by the AdRotator control. To prevent ads from executing malicious scripts, you should always check the data before releasing it, or accept ad information only from trusted sources.

To secure your advertisement file from unauthorized Internet access, do one or more of the following:

  • Store it in the Data directory, which is configured in Machine.config to deny Internet access for files of any type.

  • Rename the file with an extension that is not .xml, and map the extension to the HttpForbiddenHandler in Web.config. For more information, see the httpHandlers Element (ASP.NET Settings Schema) section in your Machine.config file.

Walkthrough: Displaying and Tracking Advertisements with the AdRotator ControlBuilding ASP .NET Web Applications in Visual Studio

The following code example demonstrates how to use the AdvertisementFile property to specify the location of the XML file that contains advertisement information.

<%@ Page Language="C#" AutoEventWireup="True" %>
    <form runat="server">
       <h3>AdRotator Example</h3>
       <asp:AdRotator id="AdRotator1" runat="server"

The following code example shows the file format of the XML advertisement file.

    <AlternateText>Microsoft Main Site</AlternateText>
    <Caption>This is the caption for Ad#1</Caption> 
    <AlternateText>Wingtip Toys</AlternateText>
    <Caption>This is the caption for Ad#2</Caption> 

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0