Creating Ads in XML

In this blog we will learn, how to create Ads in XML.

Right Click On Project Add App_Data FolderRC Add XML File

  1. <?xml version="1.0" encoding="utf-8" ?>   
  2. <Advertisements>  
  3.   <Ad>  
  4.     <ImageUrl>~/images/download (1).jpg</ImageUrl>  
  5.     <Width>300</Width>  
  6.     <Height>350</Height>  
  7.     <NavigateUrl>http://www.facebook.com/</NavigateUrl>  
  8.     <AlternateText>C-sharpcorner Home Page</AlternateText>  
  9.     <Impressions>3</Impressions>  
  10.     <Keyword>small</Keyword>  
  11.   </Ad>  
  12.   <Ad>  
  13.     <ImageUrl>~/images/download (2).jpg</ImageUrl>  
  14.     <Width>300</Width>  
  15.     <Height>350</Height>  
  16.     <NavigateUrl>http://www.jagran.com/</NavigateUrl>  
  17.     <AlternateText>C-sharpcorner Home Page</AlternateText>  
  18.     <Impressions>2</Impressions>  
  19.     <Keyword>small</Keyword>  
  20.   </Ad>  
  21.   <Ad>  
  22.     <ImageUrl>~/images/download (3).jpg</ImageUrl>  
  23.     <Width>300</Width>  
  24.     <Height>350</Height>  
  25.     <NavigateUrl>http://www.tatamotors.com/</NavigateUrl>  
  26.     <AlternateText>C-sharpcorner Home Page</AlternateText>  
  27.     <Impressions>3</Impressions>  
  28.     <Keyword>small</Keyword>  
  29.   </Ad>  
  30. <Ad>  
  31.     <ImageUrl>~/images/download (4).jpg</ImageUrl>  
  32.     <Width>300</Width>  
  33.     <Height>350</Height>  
  34.     <NavigateUrl>http://www.tatatechnologies.com/</NavigateUrl>  
  35.     <AlternateText>C-sharpcorner Home Page</AlternateText>  
  36.     <Impressions>3</Impressions>  
  37.     <Keyword>small</Keyword>  
  38.   </Ad>  
  39. <Ad>  
  40.     <ImageUrl>~/images/download (5).jpg</ImageUrl>  
  41.     <Width>300</Width>  
  42.     <Height>350</Height>  
  43.     <NavigateUrl>http://www.flipcart.com/</NavigateUrl>  
  44.     <AlternateText>C-sharpcorner Home Page</AlternateText>  
  45.     <Impressions>3</Impressions>  
  46.     <Keyword>small</Keyword>  
  47.   </Ad>  
  48. <Ad>  
  49.     <ImageUrl>~/images/download (6).jpg</ImageUrl>  
  50.     <Width>300</Width>  
  51.     <Height>350</Height>  
  52.     <NavigateUrl>http://www.amazon.com/</NavigateUrl>  
  53.     <AlternateText>C-sharpcorner Home Page</AlternateText>  
  54.     <Impressions>5</Impressions>  
  55.     <Keyword>small</Keyword>  
  56.   </Ad>  
  57. <Ad>  
  58.     <ImageUrl>~/images/download (7).jpg</ImageUrl>  
  59.     <Width>300</Width>  
  60.     <Height>350</Height>  
  61.     <NavigateUrl>http://www.apple.com/</NavigateUrl>  
  62.     <AlternateText>C-sharpcorner Home Page</AlternateText>  
  63.     <Impressions>2</Impressions>  
  64.     <Keyword>small</Keyword>  
  65.   </Ad>  
  66. </Advertisements>  
 
Add Image folder RC on Project Folder name is images and Insert Images As u want to show Ads.
 
Add WebForm RC Project and add this code:
  1. <body>  
  2.     <form id="form1" runat="server">  
  3.     <div style="margin-left:150px;" aria-haspopup="true">  
  4.      <asp:ScriptManager ID="ScriptManager1" runat="server" />  
  5.         <asp:Timer ID="Timer1" Interval="1000" runat="server" />  
  6.         <asp:UpdatePanel ID="up1" runat="server">  
  7.             <Triggers>  
  8.                 <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />  
  9.             </Triggers>  
  10.             <ContentTemplate>  
  11.                 <asp:AdRotator ID="AdRotator1" AdvertisementFile="~/App_Data/XMLAds.xml" KeywordFilter="small" runat="server"  
  12.                  BorderStyle="Dotted"/>  
  13.             </ContentTemplate>  
  14.         </asp:UpdatePanel>  
  15.     </div>  
  16.         <div style="margin-left:200px;">  
  17.   
  18.         </div>  
  19.     </form>  
  20. </body>  
Build the solution and run the application