web 2.0

Map AdRotator to a folder

Few days before one of my fellow comes up with this challenge, the requirement is good but by using it you will lose control over two thing1. Navigate URL2. Impression PriorityIf you are ready to compromise on these two then the solution is here. Please bear in mind that this is not how to of Ad rotator control. It is related to advance use. To learn basics please visitAs you all know that Ad Rotator control accept an xml file to show advertisement. the scehma of the xml file is as follow. 
 <Advertisements>
 <Ad>
  <ImageUrl>/images/expand_blue.jpg</ImageUrl>
  <NavigateUrl>www.aghausman.net</NavigateUrl>
  <AlternateText>expand_blue.jpg</AlternateText>
  <Impressions>1</Impressions>
</Ad>
 <Advertisements>
 
So to make it work dynamically, I mean by mapping to a folder we need to write an xml file each time the page load. (You can use some alternative approaches as well) First, we write to set the Adrotator on out aspx page.
<asp:AdRotator ID="AdRotator1" runat="server" /> 
 Then to generate a file using any folder I write the following function
private void bindFiles()        {            string strPath = "/images/"; //Folder Path            DirectoryInfo di = new DirectoryInfo(Server.MapPath(strPath));            if (di.Exists)            {                string filename = Server.MapPath("/upload/temp.xml");                               XmlTextWriter objtw = new XmlTextWriter(filename, System.Text.UTF8Encoding.UTF8);                objtw.WriteStartDocument();                objtw.WriteStartElement("Advertisements");                               FileInfo[] objFile = di.GetFiles("*.jpg"); //you can extract multiple format of images                foreach (FileInfo f in objFile)                {                    objtw.WriteStartElement("Ad");                    objtw.WriteStartElement("ImageUrl");                    objtw.WriteString(strPath + f.Name);                    objtw.WriteEndElement();                                       objtw.WriteStartElement("NavigateUrl");                    objtw.WriteString("#"); // Passing # means no action                    objtw.WriteEndElement();                                              objtw.WriteStartElement("AlternateText");                    objtw.WriteString(f.Name);                    objtw.WriteEndElement();                           objtw.WriteStartElement("Impressions");                    objtw.WriteString("1"); //As we don't know of any priotiry, keep it 1 for every one                    objtw.WriteEndElement();                           objtw.WriteEndElement();                }                       objtw.WriteEndElement();                objtw.WriteEndDocument();                               objtw.Flush();                objtw.Close();            }        } 
   And on the load event of page write the following stuff. 
if  (!Page.IsPostBack) {bindFiles();AdRotator1.AdvertisementFile = "/upload/temp.xml"; }
That's the whole story.

Comments

green living United States, on 11/2/2009 11:17:14 AM Said:

green living

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

Labradoodle United States, on 11/2/2009 11:32:53 AM Said:

Labradoodle

Aw, this was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate alot and never seem to get something done.

Alaskan Smoked Salmon Spread United States, on 11/3/2009 4:52:43 PM Said:

Alaskan Smoked Salmon Spread

I was looking for crucial information on this subject. The information was important as I am about to launch my own portal. Thanks for providing a missing link in my business.

Sexy Girls United States, on 11/4/2009 11:33:24 PM Said:

Sexy Girls

I am not much of a guy who thinks in so deeply about web design but I think your post had some valid points in it. Like designers are forced to design stuff within the limited code available and not go beyond it, their innovation is somewhat limited but still I think Web Design won't die! I agree that Amazon and other some big sites won't have a blog but now a days it's very important to have some sort of option available so people can quickly communicate their thoughts. I think Amazon if wants to shift it to that, they can get a customized CMS for themselves.

Horse United States, on 11/5/2009 4:53:58 PM Said:

Horse

Dude.. I am not much into reading, but somehow I got to read lots of articles on your blog. Its amazing how interesting it is for me to visit you very often.

Song Lyrics United States, on 11/7/2009 7:05:22 PM Said:

Song Lyrics

The beauty of these blogging engines and CMS platforms is the lack of limitations and ease of manipulation that allows developers to implement rich content and 'skin' the site in such a way that with very little effort one would never notice what it is making the site tick all without limiting content and effectiveness.

Linda Mirano United States, on 11/12/2009 12:30:40 PM Said:

Linda Mirano

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.

Contractor Accountants United States, on 11/14/2009 5:02:33 PM Said:

Contractor Accountants

Thank you for the sensible critique. Me & my neighbour were preparing to do some research about that. We got a good book on that matter from our local library and most books where not as influensive as your information. I am very glad to see such information which I was searching for a long time.This made very glad Smile

Restaurant Copycat Recipes United States, on 11/16/2009 3:19:35 PM Said:

Restaurant Copycat Recipes

Hrmm that was weird, my comment got eaten. Anyway I wanted to say that it's nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. This was the first place that told me the answer. Thanks.

personalized gifts United States, on 11/18/2009 3:41:49 AM Said:

personalized gifts

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

fioricet online bluelist United States, on 12/16/2009 5:54:48 PM Said:

fioricet online bluelist

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading