ARTICLE

AdRotator Standard Control

Posted by Munir Shaikh Articles | Visual C# March 14, 2007
This article will help programmer, developer to overcome the problem as:"The AdRotator adRtrCtrl/adRotator1 could not find the AdvertisementFile or the file is invalid".
Reader Level:
Download Files:
 

Recently I was working on AdRotator controll in Asp.Net 2.0, at one stage while adding Ads.xml file.

I notice following error:

Error:

The AdRotator adRtrCtrl/adRotator1 could not find the AdvertisementFile or the file is invalid.

Possible causes:

  1. Check XML file if it is in well format.
  2. Check <NavigateUrl> tag, if it is of the form http://www.csharpcorner.com/adv=Y&ID=123 .
    The ampresand & is a reserved charactor in XML so you have to use &amp.
  3. If the nature of your XML file is something of the form as listed below.

<Advertisements>

  <Adv>

    <ImageUrl>Images/1.gif</ImageUrl>

    <NavigateUrl>http://www.c-sharpcorner.com</NavigateUrl>

    <Alt>Csharp code</Alt>

    <Caption>Csharp Site</Caption>

  </Adv>

</Advertisements>

If the first element in above file is other than <Ad> then also it gives error, it has to have very first child element as <Ad>, this is what I have observed with the code.

So it takes form like.

<Advertisements>

  <Ad>

    <ImageUrl>Images/1.gif</ImageUrl>

    <NavigateUrl>http://www.c-sharpcorner.com</NavigateUrl>

    <Alt>Csharp code</Alt>

    <Caption>Csharp Site</Caption>

  </Ad>

</Advertisements>

Code for Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div style="text-align: left">

        &nbsp;<table>

            <tr>

                <td style="width: 259px">

                    <asp:Label ID="Label1" runat="server" Font-Names="Verdana" Font-Size="Smaller" Text="AdRotator
                      Component 
randomly picks up ad banners from XML file and clicking on  banner takes to the specified

                      URL" Width="301px"></asp:Label></td>

                <td style="width: 496px">

                    <asp:AdRotator ID="adRtrCtrl" Target="_self" runat="Server" />

                </td>

            </tr>

        </table>

    </div>

    </form>

</body>
</html>

Code for Ads.xml file:


<
Advertisements>

  <Ad>

    <ImageUrl>Images/1.gif</ImageUrl>

    <NavigateUrl>http://www.c-sharpcorner.com</NavigateUrl>

    <Alt>Csharp code</Alt>

    <Caption>Csharp Site</Caption>

  </Ad>

  <Ad>

    <ImageUrl>Images/1.gif</ImageUrl>

    <NavigateUrl>http://www.vbdotnetheaven.com</NavigateUrl>

    <Alt>VB.Net</Alt>

    <Caption>Visual Basic</Caption>

  </Ad>

  <Ad>

    <ImageUrl>Images/3.gif</ImageUrl>

    <NavigateUrl>http://www.c-sharpcorner.com</NavigateUrl>

    <Alt>Csharp code</Alt>

    <Caption>Csharp Site</Caption>

  </Ad>

  <Ad>

    <ImageUrl>Images/4.gif</ImageUrl>

    <NavigateUrl>http://www.mindcracker.com</NavigateUrl>

    <Alt>.Net Professional Job Site</Alt>

    <Caption>VS.Net</Caption>

  </Ad>

</Advertisements>

Note: I have tested the code 5-6 time with above error.

Login to add your contents and source code to this article
post comment
     

It is wrong b'coz in default.aspx "Advertisementfile"  property is missing from adrotator control

Posted by manish bansal Feb 04, 2010

I was having problems with this until I read this article. Thanks for doing the troubleshooting, it helped me a lot. I made a table for holding all the ad records I have. I also had a cleanup process to delete all the expired banners and what not. You decide what works best for you. Here is an example that migth help. (I am using the northwind database to do this example.) The first section makes the table and constraints you can use. The second shows you how to use SQL to get the data out of the table an into an XML format. Mind you, there are a lot of ways to do this. This happens to be simple to explain. ------------------------------------------ USE [Northwind] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Advertisements]( [AdID] [int] IDENTITY(1,1) NOT NULL, [CustomerID] [nchar](5) NOT NULL, [AdFile] [varchar](100) NULL, [AdFilePath] [varchar](100) NULL, [AdDetails] [varchar](250) NULL, [CustomerURL] [varchar](250) NULL, [InsertDate] [datetime] NULL, [InsertUser] [varchar](25) NULL, [ModDate] [datetime] NULL, [ModUser] [varchar](25) NULL, [EffectiveDate] [datetime] NULL, [ExpirationDate] [datetime] NULL, CONSTRAINT [PK_Advertisements] PRIMARY KEY CLUSTERED ( [AdID] ASC, [CustomerID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[Advertisements] WITH CHECK ADD CONSTRAINT [FK_Advertisements_Customers] FOREIGN KEY([CustomerID]) REFERENCES [dbo].[Customers] ([CustomerID]) GO ALTER TABLE [dbo].[Advertisements] CHECK CONSTRAINT [FK_Advertisements_Customers] ------------------------------------------------------------------------------------------------------------------------------------ SELECT DISTINCT 1 as Tag, NULL as Parent, '' AS [Advertisements!1], NULL AS [Ad!2!ImageUrl!Element], NULL AS [Ad!2!NavigateUrl!Element], NULL AS [Ad!2!ALT!Element], NULL AS [Ad!2!Caption!Element] UNION ALL SELECT 2 as Tag, 1 as Parent, '', 'images\'+[AdFile] AS 'ImageUrl', --your path might be different [CustomerURL] AS 'NavigateUrl', [CustomerID], -- Alt [AdDetails] -- Caption FROM [Northwind].[dbo].[Advertisements] Where GetDate() >= EffectiveDate AND GetDate() < ExpirationDate FOR XML EXPLICIT ------------------------------------------------------------------- Hope it helps someone in the efforts.

Posted by Frank Johnson Mar 27, 2009
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter