tag:blogger.com,1999:blog-34354381288452649092024-03-13T22:26:29.614+00:00using System. Web. Beginnerlynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-3435438128845264909.post-6741522573776835532011-02-19T23:22:00.000+00:002011-02-19T23:23:28.303+00:00Momento Extendo<p>Recently I have been using an iPhone app called <a href="http://momentoapp.com">Momento</a>. This is a diary app with a difference. As with any diary app, you can add diary entries complete with photos and tags. Momento also allows you to connect to web services such as Twitter, Facebook and Last.fm to populate your diary with your online activity. You can also add RSS/Atom feeds to be included in your diary. Here are the feeds I have currently in Momento:</p> <ol> <li>Foursquare </li> <li>Instapaper: Unread </li> <li>Instapaper: Archive </li> <li>Twitter </li> <li>Last.fm Loved Tracks </li> <li>Youtube </li> <li>Vimeo </li> <li>Delicious Bookmarks </li> <li>Quora: Followed Questions </li> <li>Librarything </li> <li>Github </li> <li>Assembla </li> </ol> <p>I created <a href="http://momento-extendo.heroku.com"><strong>Momento Extendo</strong></a><strong> </strong>so I could use some more Twitter related feeds with Momento:</p> <ol> <li><strong>Friendships <br /></strong>Followed Friends <br />Unfollowed Friends </li> <li><strong>Lists <br /></strong>New Lists <br />Added List Members <br />Removed List Members <br />Added Subscribed Lists <br />Unsubscribed Lists </li> </ol> <p>I thought this would be a good opportunity to learn some Ruby an try hosting an app on <a href="http://heroku.com">Heroku</a>. I choose <a href="http://www.sinatrarb.com/">Sinatra</a> as the web framework because it was lightweight, easy to learn and took little to no time to get up and running. A couple of Heroku add-ons I used were <a href="http://apigee.com/about/products_free.html">Apigee</a> for Twitter and <a href="https://cloudant.com/solutions/cloud">Cloudant</a> Hosted <a href="http://couchdb.apache.org/">CouchDB</a>. Apigee provide a proxied Twitter Api endpoint that gives you a whitelisted rate limit (20k reqs/hour). The free Cloudant hosted CouchDB solution offers 250 MB of storage with a hosted <a href="http://couchdb.apache.org/screenshots.html">Futon</a> admin.</p> <p>The main purpose of the app is to regularly poll Twitter to detect changes in a user’s friends and lists in order to provide a feed of these changes which can be used with Momento. This polling is required because, <a href="http://groups.google.com/group/twitter-development-talk/browse_thread/thread/3862a9819f17839d/aa834ba2cef41b1b">at the moment</a>, Twitter does not included timestamps with friendship-follow/unfollow or list activities. Initially, I thought about using <a href="http://devcenter.heroku.com/articles/delayed-job">Delayed Jobs</a> to take care of the polling but this would involve using a background worker process for which Heroku charges for. As the app is going to have fairly low traffic and the single HTTP process or ‘Dyno’ can handle between 10 and 100 requests per second, I started looking for a solution that could ping the app periodically over HTTP.</p> <p>I found <a href="http://momentapp.com/">Moment</a>, a service that allows you to create a delayed job that makes an HTTP request at the time specified.</p> <p><a href="http://lh6.ggpht.com/_SRluay1L3S8/TWBNL21SORI/AAAAAAAAAOI/P9YfC_SrGj0/s1600-h/moment%5B1%5D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="moment" border="0" alt="moment" src="http://lh3.ggpht.com/_SRluay1L3S8/TWA-sCQ6qPI/AAAAAAAAAOM/dn2nE2t3aEQ/moment_thumb.png?imgmax=800" width="518" height="380" /></a></p> <p>I use the <a href="http://addons.heroku.com/cron">Daily Cron</a> Heroku add-on to remove any completed Moment jobs.</p> <p><strong>Heroku Add-Ons</strong></p> <ul> <li><a href="http://apigee.com/about/products_free.html">Apigee for Twitter</a> </li> <li><a href="https://cloudant.com/solutions/cloud">Cloudant CouchDB</a> </li> <li><a href="http://addons.heroku.com/cron">Daily Cron</a> </li> </ul> <p><strong>Gems</strong></p> <ul> <li><a href="http://rubygems.org/gems/sinatra">Sinatra</a> – lightweight web framework </li> <li><a href="http://rubygems.org/gems/twitter">Twitter</a> – Twitter Api client </li> <li><a href="http://rubygems.org/gems/twitter_oauth">Twitter OAuth</a> </li> <li><a href="http://rubygems.org/gems/couchrest">CouchRest</a> – Provides a wrapper around the CouchDB http api </li> <li><a href="http://rubygems.org/gems/rufus-mnemo">Rufus-Mnemo</a> – Tokenizer using syllables from the Japanese language </li> </ul> <p><strong>Final Result</strong></p> <p>Some items from my Twitter Friendships feed in Momento:</p> <p><a href="http://lh6.ggpht.com/_SRluay1L3S8/TWBNMr0XsEI/AAAAAAAAAOQ/FOc6qqtMI6Y/s1600-h/Photo%20Feb%2019%2C%2022%2059%2051%5B7%5D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Photo Feb 19, 22 59 51" border="0" alt="Photo Feb 19, 22 59 51" src="http://lh4.ggpht.com/_SRluay1L3S8/TWBNNPODxqI/AAAAAAAAAOU/qxKQi3w4HbM/Photo%20Feb%2019%2C%2022%2059%2051_thumb%5B9%5D.jpg?imgmax=800" width="275" height="400" /></a></p> lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com0tag:blogger.com,1999:blog-3435438128845264909.post-73924599072428600692009-09-30T00:46:00.001+01:002009-09-30T00:46:31.960+01:00Keystroke Launchers – A Developer’s Best Friend<p><a href="http://www.launchy.net">Launchy</a> is an open source keystroke launcher that has been around since 2007. I had used it in the past but without any real purpose and I didn’t give it enough time or attention to discover its numerous applications. Recently I have being using it at work to reduce some of the time I spend looking for and clicking on toolbar and quick-launch shortcuts. When writing code, the last thing I want to do is have to reach for the mouse and dig around for a shortcut. I can run Launchy from within any application by using the Alt+Space keyboard shortcut.</p> <p>Launchy assigns keywords to certain actions and runs a search for your input to find any matching keywords. The key to using Launchy effectively is to keep the number of shortcuts and commands to the bare minimum so that the keywords you use will match the shortcut/command you want to execute.</p> <p><strong>1) Apps and Folders</strong></p> <p>Launchy will index all of the shortcuts and folders in your start menu (as does the search in Vista and Windows 7 start menus).</p> <p><a href="http://lh4.ggpht.com/_SRluay1L3S8/SsKcLTTUJ2I/AAAAAAAAAHg/CUJM4wbco5g/s1600-h/image%5B79%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_SRluay1L3S8/SsKcL-BDtpI/AAAAAAAAAHk/CjER_i3jfyk/image_thumb%5B61%5D.png?imgmax=800" width="538" height="118" /></a> </p> <p><a href="http://lh4.ggpht.com/_SRluay1L3S8/SsKcMfo4FvI/AAAAAAAAAHo/kIMmn727X4k/s1600-h/image%5B95%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_SRluay1L3S8/SsKcNXLWUwI/AAAAAAAAAHs/rG8k7GtoJQQ/image_thumb%5B74%5D.png?imgmax=800" width="538" height="229" /></a> </p> <p><strong></strong></p> <p><strong>2) Solutions</strong></p> <p>By indexing your development folder for *.sln and *.csproj files, you can open up a solution/project in Visual Studio without having to go to Windows Explorer or the VS Start Page!</p> <p><a href="http://lh3.ggpht.com/_SRluay1L3S8/SsKcN1AhBCI/AAAAAAAAAHw/KzB5znmA464/s1600-h/image%5B81%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_SRluay1L3S8/SsKcOWEnEJI/AAAAAAAAAH0/KGE8Gf1ggvU/image_thumb%5B63%5D.png?imgmax=800" width="538" height="121" /></a> </p> <p><a href="http://lh6.ggpht.com/_SRluay1L3S8/SsKcO4acMgI/AAAAAAAAAH4/cmnvVr2H004/s1600-h/image%5B80%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_SRluay1L3S8/SsKcP9X89CI/AAAAAAAAAH8/JrOdqy3sjvY/image_thumb%5B62%5D.png?imgmax=800" width="538" height="237" /></a> </p> <p><strong></strong></p> <p><strong>3) Runner Plugin</strong></p> <p>Launchy comes with a Runner and Weby plugin that you can use to run program and web based commands. Let’s look at the Runner plugin first.</p> <p>You can setup runner commands to link a program with a keyword and allow user input:</p> <p><a href="http://lh5.ggpht.com/_SRluay1L3S8/SsKcQZRRgfI/AAAAAAAAAIA/zKdBluAP0zE/s1600-h/image%5B87%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_SRluay1L3S8/SsKcRBKEy1I/AAAAAAAAAIE/3TRsbNX_JZg/image_thumb%5B67%5D.png?imgmax=800" width="538" height="133" /></a> </p> <p>A command can be executed by entering [Keyword] <em>Tab</em> [Parameter]:</p> <p><a href="http://lh4.ggpht.com/_SRluay1L3S8/SsKcRXocp0I/AAAAAAAAAII/9nsUuAbqahM/s1600-h/image%5B82%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_SRluay1L3S8/SsKcR0H8nYI/AAAAAAAAAIM/UxRIEt_URsI/image_thumb%5B64%5D.png?imgmax=800" width="538" height="116" /></a> </p> <p><a href="http://lh5.ggpht.com/_SRluay1L3S8/SsKcSer1r-I/AAAAAAAAAIQ/WEf51Fz7aCU/s1600-h/image%5B59%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_SRluay1L3S8/SsKcTAUxoLI/AAAAAAAAAIU/eFnRT-coclU/image_thumb%5B43%5D.png?imgmax=800" width="538" height="113" /></a> </p> <p><strong></strong></p> <p><strong>4) Weby Plugin and Custom Searches</strong></p> <p>Launchy will index your browser bookmarks by default (IE and FF) and comes with a slew of searches such as Google, Wikipedia, Amazon etc. You can add to these and I’ve added a couple of custom Twitter searches:</p> <p><a href="http://lh5.ggpht.com/_SRluay1L3S8/SsKcTnEk0uI/AAAAAAAAAIY/Pv56ozIpniE/s1600-h/image%5B65%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_SRluay1L3S8/SsKcT3oE1uI/AAAAAAAAAIc/ANue_06yI7A/image_thumb%5B53%5D.png?imgmax=800" width="526" height="55" /></a> </p> <p>Running the search commands follows the same [Keyword] <em>Tab </em>[Parameter]pattern as the Runner.</p> <p>hash <em>Tab</em> fail would give:</p> <p><a href="http://lh4.ggpht.com/_SRluay1L3S8/SsKcUXC0lNI/AAAAAAAAAIg/4J8UsaDa3ro/s1600-h/image%5B71%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_SRluay1L3S8/SsKcU8OtPOI/AAAAAAAAAIk/V-CfreaJ7uw/image_thumb%5B57%5D.png?imgmax=800" width="538" height="111" /></a> </p> <p>and wiki <em>Tab </em>launchy would give:</p> <p><a href="http://lh6.ggpht.com/_SRluay1L3S8/SsKcVTTqqLI/AAAAAAAAAIo/wuyUfB-c6o4/s1600-h/image%5B75%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_SRluay1L3S8/SsKcVvrlKcI/AAAAAAAAAIs/03st4T36ZEg/image_thumb%5B59%5D.png?imgmax=800" width="538" height="118" /></a></p> lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com0tag:blogger.com,1999:blog-3435438128845264909.post-89858583298835198372009-04-28T09:38:00.001+01:002009-04-28T16:55:56.253+01:00bdUnit – It’s back<p>I have been really busy lately so I haven’t been able to give <a href="http://usingsystembeginner.blogspot.com/2009/02/bdunit-bdd-unit-test-dsl-using.html">bdUnit</a> the attention it deserves. This week I have started adding features again and I thought it would be a good time to put up a video on using bdUnit with a VS project…</p> <p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler_lynchjames_3"><param name="wmode" value="transparent" /><param name="movie" value="http://www.viddler.com/player/98417b36/" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/player/98417b36/" wmode="transparent" width="437" height="370" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="viddler_lynchjames_3" /></embed></object></p> <p><a href="http://cid-bb9eb1d1acd94f63.skydrive.live.com/self.aspx/Resources/bdUnit-walkthrough.wmv" target="_blank">Download bdUnit-walkthrough.wmv directly</a></p> <p>I briefly talk about a couple of the DSL features at the end of the video but I will put up a more in-depth post on this later in the week.</p> lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com0tag:blogger.com,1999:blog-3435438128845264909.post-45724987379420587912009-02-19T14:31:00.003+00:002009-03-19T09:30:34.911+00:00bdUnit.Preview Demo<p>I have been working on a few new features over the past couple of evenings (and early mornings!) and I’ve made a short demo video of the current state of the preview app.</p> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="viddler_c7cb15f" width="545" height="451"><param name="wmode" value="transparent"><param name="movie" value="http://www.viddler.com/player/c7cb15f/"><param name="allowScriptAccess" value="always"><param name="allowFullScreen" value="true"><embed src="http://www.viddler.com/player/c7cb15f/" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_c7cb15f" wmode="transparent" width="545" height="451"></embed></object> <p> </p> <p>The video runs through the following features:</p> <ul> <li>Input syntax highlighting</li> <li>Tests generated in nUnit, xUnit and MbUnit</li> <li>Parsing error handling and reporting within the app</li> <li>Error highlighted within input text</li> <li>Clickable error links to position in input text</li> </ul> <p>I was aiming to get at least some of the cool features from Intellipad but with an ‘end-to-end’ preview rather than the tree-preview/mgraph view offered by Intellipad. I took this approach from the <a href="http://blogs.msdn.com/joshwil/archive/2008/11/12/using-mgrammar-to-create-net-instances-through-xaml.aspx">MGrammar Xaml sample</a> produced by SpankyJ.<br /></p> <p>I am now going to concentrate on extending the MGrammar at the heart of the project and hope to have an update on this within a week or so.</p>lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com0tag:blogger.com,1999:blog-3435438128845264909.post-42223577440215078032009-02-13T07:30:00.015+00:002010-01-29T21:32:17.908+00:00Compiling a Dll Programmatically using CSharpCodeProvider<p>For <a href="http://usingsystembeginner.blogspot.com/2009/02/bdunit-bdd-unit-test-dsl-using.html">bdUnit</a>, I needed to output the generated source code as a compiled dll. I was dreading this but, when I bit the bullet, the code turned out to be pretty clean and simple:</p><pre class="brush: csharp"><br />using System;<br />using System.CodeDom.Compiler;<br />using System.Collections.Generic;<br />using System.IO;<br />using System.Text;<br />using bdUnit.Core;<br />using Core.Enum;<br />using Microsoft.CSharp;<br /><br />namespace bdUnit.Core<br />{<br /> public class DllBuilder<br /> {<br /> private readonly string[] References =<br /> new[] {<br /> "Rhino.Mocks", "nunit.core", "nunit.core.interfaces", "nunit.framework",<br /> "xunit", "MbUnit.Framework", "StructureMap", "StructureMap.AutoMocking"<br /> };<br /><br /> public string CompileDll(string folderPath, UnitTestFrameworkEnum currentFramework)<br /> {<br /> CodeDomProvider compiler = <br /> new CSharpCodeProvider(new Dictionary<string, string>{{"CompilerVersion","v3.5"}});<br /> <br /> var parameters = new CompilerParameters<br /> {<br /> GenerateInMemory = false,<br /> GenerateExecutable = false,<br /> IncludeDebugInformation = true,<br /> OutputAssembly = string.Format("bdUnit_{0}.dll", currentFramework),<br /> ReferencedAssemblies = {"System.dll"}<br /> };<br /> <br /> foreach (var reference in References)<br /> {<br /> parameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory<br /> + string.Format("\\{0}.dll", reference));<br /> }<br /> var source = GetSource(folderPath, currentFramework);<br /> var results = compiler.CompileAssemblyFromSource(parameters, source);<br /> <br /> if (results.Errors.HasErrors)<br /> {<br /> var errorText = new StringBuilder();<br /> var count = results.Errors.Count;<br /> for (var i = 0; i < count; i++)<br /> {<br /> errorText.AppendLine("Compilation Error: " + results.Errors[i].ErrorText);<br /> }<br /> return errorText.ToString();<br /> }<br /> return "Succesfully Generated Dll";<br /> }<br /><br /> private static string[] GetSource(string folderPath, UnitTestFrameworkEnum framework)<br /> {<br /> Directory.SetCurrentDirectory(folderPath);<br /> var files = Directory.GetFiles(folderPath, "*.input");<br /> var source = new string[files.Length];<br /> for (var i = 0; i < files.Length; i++)<br /> {<br /> var paths = new Dictionary<string, string><br /> {<br /> {"input", string.Format("{0}", files[i])},<br /> {"grammar", Settings.GrammarPath}<br /> };<br /> var parser = new Parser(paths);<br /> source[i] = parser.Parse(framework);<br /> }<br /> return source;<br /> }<br /> }<br />}<br /></pre><p>I setup my compile parameters with the framework and references that I need. Note that these references are only present as includes and the corresponding dlls need to be present in the bin folder where the dynamically compiled dll is used. There may also be issue at runtime if different versions of such dependancies are referenced in the dll and present in the bin folder.</p><p>I use the GetSource method to parse the inputs/user stories and construct an array of source code, each member representing a .cs file. I then pass this as an argument for CompileAssemblyFromSource and report any errors that prevent the compilation from completing. The errors are informative and cover missing/misnamed references as well as build errors in the source code itself.<br /></p><p>In the next post I will run through further developments to the MGrammar used in bdUnit including support for new input statements and steps I have taken to refactor the grammar itself.</p><p><br /></p><p>James Lynch</p>lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com2tag:blogger.com,1999:blog-3435438128845264909.post-45452284595127694972009-02-08T22:30:00.015+00:002010-01-29T22:01:05.541+00:00bdUnit A BDD - Unit Test DSL using Microsoft Oslo<p><em>[Cross posted on the </em><a href="http://blog.stormid.com/" target="_blank">StormID</a> <a href="http://blog.stormid.com/" target="_blank">blog</a><em></em><em>]</em></p><p></p><p>Over the past few weeks, I have been working on bdUnit, a side project to create a DSL that would transform user stories into C# unit tests. In November last year Jonny, one of my colleagues at Storm, tasked me with creating a parser that would generate unit tests from user stories. This was to be a part (‘APE’) of the project he named ESCAPE - ‘Evolutionary Service Compiler’ and ‘Application Programming Environment’.</p> <h3>The Parser</h3> <p>This was a rather daunting task and my first step was to look around for some tools or a framework I could use. As luck would have it, I quickly came across the <a href="http://channel9.msdn.com/pdc2008/TL31/" target="_blank">"Oslo": Building Textual DSLs PDC 2008 session</a>. I was impressed by the power, flexibility and control that Oslo offered as well as the great tool included in the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=f2f4544c-626c-44a3-8866-b2a9fe078956&displaylang=en" target="_blank">Oslo SDK</a> – Intellipad. I also came across <a href="http://www.claudioperrone.com/blog/articles/2008/11/09/misbehave-01-oslos-mgrammar-for-bdd-executable-specifications/" target="_blank">MisBehave</a> a nice implementation of the DSL componet of Oslo, MGrammar, used to create executable specifications from user stories. I realised that a similar approach could be used to extend this to executable unit tests.</p> <p>I was able to get started with considerable help from a couple of great posts by Torkel Ödegaard on <a href="http://www.codinginstinct.com/2008/11/creating-watin-dsl-using-mgrammar.html" target="_blank">Creating a WatiN DSL using MGrammar</a> and the second part, <a href="http://www.codinginstinct.com/2008/11/browser-automation-dsl-using-mgrammar.html">Browser Automation DSL using MGrammar</a>.</p> <p>Here is a view of my grammar and an example input loaded in Intellipad:</p> <p><a href="http://lh3.ggpht.com/_SRluay1L3S8/SY9c8vR5x7I/AAAAAAAAAE8/0-b12ZIKpWI/s1600-h/bdUnitMGrammar%5B2%5D.png"><img style="border-width: 0px; display: inline;" title="bdUnitMGrammar" alt="bdUnitMGrammar" src="http://lh3.ggpht.com/_SRluay1L3S8/SY9c9PzfTXI/AAAAAAAAAFA/LVv07Z3j9VM/bdUnitMGrammar_thumb.png?imgmax=800" width="244" border="0" height="148" /></a></p> <p>The input is transformed using the token matching and syntax rules contained within the MGrammar to output what I would call ‘Structured Data’ and Microsoft have named MGraph. MGraph is very similar in concept to Xml – i.e. enabling the serialization of data in a structured format that can be extended and controlled by the developer. The advantage MGrammar has over an Xml or JSON serialization is that the provision of functional text and text pattern matching logic ‘out of the box’.</p> <h3>Deserializing</h3> <p>In order to make use of the structured data provided by the parser, I needed to deserialize the data and map it on to objects I could use in C#. Again, following <a href="http://www.codinginstinct.com/2008/11/browser-automation-dsl-using-mgrammar.html" target="_blank">Torkel</a> and <a href="http://rogeralsing.com/2008/11/22/linqing-mgrammar-to-cil" target="_blank">Roger Alsing</a>’s lead, I created an <a href="http://en.wikipedia.org/wiki/Abstract_syntax_tree" target="_blank">Abstract Syntax Tree</a> (AST) to resolve the data to CIL objects. My AST is below:</p> <p><a href="http://lh5.ggpht.com/_SRluay1L3S8/SY9c9jlfhDI/AAAAAAAAAFE/oXq6FsBsHdE/s1600-h/bdUnitAST%5B2%5D.png"><img style="border-width: 0px; display: inline;" title="bdUnitAST" alt="bdUnitAST" src="http://lh6.ggpht.com/_SRluay1L3S8/SY9c9xr_HzI/AAAAAAAAAFI/FTYV737k_rk/bdUnitAST_thumb.png?imgmax=800" width="176" border="0" height="244" /></a> </p> <h3>Give Me the Code</h3> <p>Resolving the data to CIL objects enabled me to use types and type properties in generating the C# unit test.</p><pre class="brush: csharp">public string GenerateMethodSignature(CreateMethod method)<br />{<br /> var methodText = MethodText.Replace("##accesslevel##", Access.ToString());<br /> var _params = new StringBuilder();<br /> var signature = methodText.Replace("##methodname##", method.TargetMethod.Name);<br /> signature = signature.Replace("##returntype##", "void");<br /> var paramCount = method.TargetMethod.Objects.Count;<br /> for (var j = 1; j < paramCount; j++)<br /> {<br /> var parameter = method.TargetMethod.Objects[j];<br /> var instanceName = "";<br /> if (!string.IsNullOrEmpty(parameter.Instance.Value))<br /> {<br /> instanceName = parameter.Instance.Value;<br /> }<br /> else<br /> {<br /> instanceName = parameter.Name.ToLower();<br /> }<br /> var delimiter = j < (paramCount - 1) ? ", " : string.Empty;<br /> _params.Append(string.Format("I{0} {1}{2}", parameter.Name, instanceName, delimiter));<br /> }<br /> signature = signature.Replace("##params##", _params.ToString());<br /> return signature;<br />}</pre><p>I created a basic demo app in WPF to show the user story input alongside the corresponding C# output:</p><p><a href="http://lh3.ggpht.com/_SRluay1L3S8/SY9c-97ICtI/AAAAAAAAAFM/OXIwz1QRPRM/s1600-h/bdUnitPreview%5B2%5D.png"><img style="border-width: 0px; display: inline;" title="bdUnitPreview" alt="bdUnitPreview" src="http://lh3.ggpht.com/_SRluay1L3S8/SY9c_Lk7AxI/AAAAAAAAAFQ/Uw6ql4bMhLk/bdUnitPreview_thumb.png?imgmax=800" width="244" border="0" height="189" /></a> </p>With a few modifications, I was able to generate C# unit tests using the nUnit, xUnit and MbUnit frameworks.<br /><ul><li><a href="http://csodqg.bay.livefilestore.com/y1px202kxaWJ8utHhFDAQ3szMfmz2aGC5GK1or_fHVUSVJFbW4VXWsjxfJ_qhbYZoIEpP3Y7eyw_8KSguWHU3GG9g/LogansRun.input?download" target="_blank">Example input</a><br /></li><li><a href="http://csodqg.bay.livefilestore.com/y1px202kxaWJ8uxNUJ2076GgAOieXpLz8xvzPBAXiqZxqSsziGKngrXwophMS4HPJ74S2nRNdOf1uokZZcoc5OWog/bdUnit-nUnitOutput.html" target="_blank">nUnit output</a><br /></li><li><a href="http://csodqg.bay.livefilestore.com/y1px202kxaWJ8vScwJPO79yX2cEK85Qjk72w95Memxof88E2dmsQZts0jPECjSLCy3yxWL4nTy7bfuuMvy3O99Zcw/bdUnit-xUnitOutput.html" target="_blank">xUnit output</a><br /></li><li><a href="http://csodqg.bay.livefilestore.com/y1px202kxaWJ8vlU7mLQYIjrs_SKuP6EG0QJelzl6w8w8QWcKQTxUEVf2zlwW37IviWWsSDxVjomTRpyiYehOYC_g/bdUnit-MbUnitOutput.html" target="_blank">MbUnit output</a> </li><br /></ul>Notice the objects are created as Interfaces only and are instantiated within the unit tests using <a href="http://structuremap.sourceforge.net/Default.htm" target="_blank">StructureMap</a>. I did this so that the code could be used as a black box referenced dll within any project. Here is the compiled dll in <a href="http://www.red-gate.com/products/reflector/" target="_blank">Reflector</a>:<br /><p><a href="http://lh4.ggpht.com/_SRluay1L3S8/SY9c_pbGD-I/AAAAAAAAAFU/mjZ50fY25D8/s1600-h/bdUnitReflector%5B2%5D.png"><img style="border-width: 0px; display: inline;" title="bdUnitReflector" alt="bdUnitReflector" src="http://lh4.ggpht.com/_SRluay1L3S8/SY9dAIVoH9I/AAAAAAAAAFY/DZUe2ZWD94M/bdUnitReflector_thumb.png?imgmax=800" width="198" border="0" height="244" /></a> </p>Once a reference is added, concrete classes can be created and implement the bdUnit interfaces. In order for these concrete classes to be instantiated and used within the bdUnit test, they need to be maked up with the correct attribute. This allowed me to leave out any mention of these objects within the bdUnit.dll to hold the separation of concerns that would prevent the bdUnit generated code from interfering with implementation code within the client application/project.<br /><br /><pre class="brush: csharp"><br />[Pluggable("bdUnit")]<br />public class User : IUser<br />{<br /> public User(){}<br /><br /> public IUser Spouse { get; set; }<br /> public bool IsARunner { get; set; }<br /> public int Age { get; set; }<br /> public bool IsDead { get; set; }<br /> public IList<IUser> Children { get; set; }<br /><br /> public void Kill(IUser user)<br /> {<br /> user.IsDead = true;<br /> }<br /><br /> public void Marry(IUser user)<br /> {<br /> this.Spouse = user;<br /> user.Spouse = this;<br /> }<br /><br /> public void Visit(ISleepShop sleepshop)<br /> {<br /> this.IsDead = true;<br /> }<br /><br /> public void Total()<br /> {<br /> throw new System.NotImplementedException();<br /> }<br />}</pre><br /><br />It appears that StructureMap does not support the instantiation of concrete classes across dll’s without using the decalritive attributes and .GetNamedInstance<>() but this may not be the case.<br /><p>The tests can be run from the bdUnit.dll using a test-runner but unfortunately Resharper and Visual Studio only pick up tests within the source code of the application, and not those within a reference. It would be great to find a workaround for this to get the tests to run within the VS IDE.<br /></p><p>The real application of bdUnit (which only become clear very recently!) is to use ‘<a href="http://martinfowler.com/bliki/BusinessReadableDSL.html" target="_blank">Business Readable</a>’ BDD user stories to provide the developer with a working technical specification or contract to be fulfilled by their implementation code without the former interfering with the latter If some of the bdUnit tests fail, the user stories can be modified and the interfaces/unit tests regenerated or the developer can make modifications to their code.<br /></p><h3>Next Steps<br /></h3><ol><br /><li><span style="color: rgb(102, 102, 102);"><strong>Developing the MGrammar.</strong> I need to allow for more complex relationships between objects, nesting methods within methods (e.g. When @Person(John) #Purchase @House(number34) (John) should #Pay (number34) ~Price and (John) should #Pay (number34) ~StampDuty) and support types such as DateTime, Guid etc.</span><br /></li><li><span style="color: rgb(102, 102, 102);"><strong>Code Generation. </strong>This presently only supports analogues of Assert.IsTrue(clause) with comparisons being made in the clause. It would be good to make use of some of the wide variety of Asserts available.</span><br /></li><li><span style="color: rgb(102, 102, 102);"><strong>Improve Error Feedback. </strong>This is mostly nonexistent at the moment and I definitely need to provide useful exceptions at the parsing an compiling steps.</span><br /></li></ol><br /><p>James Lynch</p><p>del.icio.us Tags: <a href="http://del.icio.us/popular/microsoft+oslo" rel="tag">microsoft oslo</a>,<a href="http://del.icio.us/popular/mgrammar" rel="tag">mgrammar</a>,<a href="http://del.icio.us/popular/dsl" rel="tag">dsl</a>,<a href="http://del.icio.us/popular/bdd" rel="tag">bdd</a></p>lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com3tag:blogger.com,1999:blog-3435438128845264909.post-51058462086294551602008-12-06T00:30:00.004+00:002008-12-06T10:05:51.301+00:00Google Reader’s New Clothes<p>First post in a while but I’m hoping to find time over the next few weeks to write about some of the things I’ve been up to lately including working with Silverlight, MVC and some good ‘old-fashioned’ .NET 3.5. Next post will be on my experiences with the possibilities (and the steep learning curve) given by the <a href="http://msdn.microsoft.com/en-us/oslo/default.aspx" target="_blank">Microsoft Oslo</a> platform.</p> <p>Since it’s a Friday I thought I would put up a <strike>quick</strike> post inspired by the new look Google Reader released today with details on the <a href="http://googlereader.blogspot.com/2008/12/square-is-new-round.html" target="_blank">official blog</a>. I thought I would go my own way with the <a href="http://helvetireader.com/" target="_blank">Helvetireader</a> theme (using <a href="https://addons.mozilla.org/en-US/firefox/addon/748" target="_blank">GreaseMonkey</a> to support the scipt) for now and I like the streamlined, clean approach…</p> <p><a href="http://lh6.ggpht.com/_SRluay1L3S8/STnHe13NUoI/AAAAAAAAAD0/p6nyDFlqs9Y/s1600-h/Helvetireader%5B2%5D.png"><img style="border-width: 0px; float: none; margin-left: auto; margin-right: auto; display: block;" title="Helvetireader" alt="Helvetireader" src="http://lh5.ggpht.com/_SRluay1L3S8/STnHfm85r1I/AAAAAAAAAD8/esYr-SOThqQ/Helvetireader_thumb.png?imgmax=800" border="0" width="244" height="130" /></a> </p> <p>However, it’s clear that some real estate was being wasted so I changed tack and chose to use the standalone Helvetireader CSS with Stylish to allow me to tweak it slightly:</p> <ol> <li>Changed the max width so that there is no whitespace when reading with the subscriptions panel open <br /><span style="color: rgb(0, 128, 128);font-family:cali;font-size:85%;" > <br />.entry .entry-body, .entry .entry-title { <br /> max-width:1000px; <br />} <br /></span></li> <li>Removed the post entry options background images as this was overlapped by the options themselves when the Preview function was in place </li> </ol> <p>This gave a good result..</p> <p><a href="http://lh3.ggpht.com/_SRluay1L3S8/STnHgaDQZJI/AAAAAAAAAEA/fLCa4qyFSnk/s1600-h/Helvetireader-with-changes%5B2%5D.png"><img style="border-width: 0px; float: none; margin-left: auto; margin-right: auto; display: block;" title="Helvetireader-with-changes" alt="Helvetireader-with-changes" src="http://lh4.ggpht.com/_SRluay1L3S8/STnHgpvseFI/AAAAAAAAAEE/s2rIWlIUXR4/Helvetireader-with-changes_thumb.png?imgmax=800" border="0" width="244" height="131" /></a></p> <p>The tweaked CSS can be found <a href="http://sites.google.com/site/lynchjamesfiles/Home/Helvetireader.css" target="_blank">here</a>. </p> <p>The good thing about using either a GreaseMonkey script or a Stylish theme is that I can preserve the great functions offered by <a href="https://addons.mozilla.org/en-US/firefox/addon/6424" target="_blank">Better GReader</a>, an essential Firefox extension which I have been using for some time. It looks like the Preview post function is not working in the latest version (v0.4). I reinstated this by installing the GreaseMonkey script provided by <a href="http://userscripts.org/users/21436" target="_blank">Julien Carosi</a> at <a href="http://userscripts.org/scripts/show/9455" target="_blank">userscripts.org</a> (making the changes given in a <a href="http://userscripts.org/topics/18585" target="_blank">comment</a> on the script).</p> <p>This function is great as it enables you to stay within Google Reader while viewing the blog as it appears in its original form, either to view/post comments or read the entire post if the blogger has only provided a snippet/teaser via RSS. </p> <p><a href="http://lh6.ggpht.com/_SRluay1L3S8/STnHhaxTVYI/AAAAAAAAAEI/5E3AGgxfaxg/s1600-h/Post%20Snippet%5B2%5D.png"><img style="border-width: 0px; margin-left: 0px; margin-right: 0px; display: inline;" title="Post Snippet" alt="Post Snippet" src="http://lh6.ggpht.com/_SRluay1L3S8/STnHhxnRTKI/AAAAAAAAAEM/7bw9OKlVQJQ/Post%20Snippet_thumb.png?imgmax=800" align="left" border="0" width="244" height="131" /></a> <a href="http://lh3.ggpht.com/_SRluay1L3S8/STpNCQ3b4mI/AAAAAAAAAEs/vGM-aOLvACQ/s1600-h/Post%20Preview%5B2%5D.png"><img style="border-width: 0px; display: inline;" title="Post Preview" alt="Post Preview" src="http://lh5.ggpht.com/_SRluay1L3S8/STpNC_svgiI/AAAAAAAAAEw/H202sQfXApk/Post%20Preview_thumb.png?imgmax=800" border="0" width="244" height="131" /></a></p> <p>To be honest, this practice annoys me and <a href="http://allinthehead.com/retro/272/more-after-the-jump" target="_blank">others</a>. It would be understandble if this was the only way to provide marketing content but blogs such as <a href="http://feeds.feedburner.com/LosTechies/" target="_blank">Los Techies</a> have proved otherwise. Luckily, with technical/development blogs, ‘after the jump’ syndrome is relatively rare perhaps due to the tech bloggers being keen consumers of syndicated content.</p>lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com0tag:blogger.com,1999:blog-3435438128845264909.post-44626125490972091832008-07-13T23:08:00.004+01:002008-07-19T17:51:03.647+01:00Image Gallery and AdRotatorFirst post, and some of my first real C# coding!<br /><br />Following a couple of examples in <a href="http://www.informit.com/store/product.aspx?isbn=0672330113">Asp.Net 3.5 Unleashed</a>, I created a form that uploaded images to an image gallery which was displayed on the same page. To improve on this, I added the option to select the type of image to be added.<br /><br />A 'Gallery' image would be saved to /Assets/Images and displayed in the image gallery. An 'Advert' image would be saved to another folder and the accompanying details (ImageUrl, NavigateUrl and AltText) written to an xml file.<br /><pre><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" ><br />using</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > System;<o:p></o:p></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" ><br />using</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > System.Xml;<o:p></o:p></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" ><br />using</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > System.IO;<o:p></o:p></span><span style="font-size:100%;"> </span><p class="MsoNormal" style=""><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >partial</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >class</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >WebUserControl</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > : System.Web.UI.</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >UserControl<br />{<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >public</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >void</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > Page_Load(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >Object</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > sender, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >EventArgs</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > e)<o:p></o:p></span><span style="font-size:100%;"><br /></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span>{<br /><span style=""> </span>btnImage.Click += (Button_Click);<br /><span style=""> </span>}<o:p><br /></o:p><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >protected</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >bool</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > imageIsAd;<o:p></o:p></span><span style="font-size:100%;"><br /></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >protected</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >void</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > AdRadio_CheckedChanged(</span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >object</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > sender, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >EventArgs</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > e)<br /><span style=""> </span>{<span style=""><br /></span> imageIsAd = </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >true</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >;<br /><span style=""> </span>}<o:p><br /></o:p><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >protected</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >void</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > GalleryRadio_CheckedChanged(</span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >object</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > sender, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >EventArgs</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > e)<o:p></o:p></span><span style="font-size:100%;"><br /></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span>{<br /><span style=""> </span>imageIsAd = </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >false</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >;<br /><span style=""> </span>}<o:p><br /></o:p></span></p><p class="MsoNormal" style=""><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><o:p></o:p><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >public</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >void</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > Button_Click(</span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >object</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > sender, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >EventArgs</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > e)<o:p></o:p></span><span style="font-size:100%;"> </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""><br /></span>{<o:p></o:p><span style=""><br /></span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >if</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > (!imageUpload.HasFile) </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >return</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >;<o:p></o:p><span style=""><br /></span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >if</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > (!imageIsAd)<o:p></o:p></span><span style="font-size:100%;"> </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""><br /></span>{ <o:p></o:p></span><span style="font-size:100%;"> <span style="font-family:Consolas;"><br /></span></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > filePath = </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"~/Assets/Images/"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > + imageUpload.FileName;<br /><span style=""> </span>imageUpload.SaveAs(MapPath(filePath));<br /><span style=""> </span>}<o:p><br /><br /></o:p><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > adPath = </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"~/Assets/Ads/"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > + imageUpload.FileName;<o:p></o:p></span><span style="font-size:100%;"><br /></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span>imageUpload.SaveAs(MapPath(adPath));<br /><span style=""> </span>WriteXml();<br /><span style=""> </span>ImageLink.Text = </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >String</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >.Empty;<br /><span style=""> </span>AltText.Text = </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >String</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >.Empty;<br /><span style=""> </span>}<br /><o:p> </o:p></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><o:p></o:p></span><span style="font-size:100%;"><br /></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >void</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > Page_PreRender()<o:p></o:p></span><span style="font-size:100%;"><br /></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span>{<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > imgFolder = MapPath(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"~/Assets/Images/"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > dir = </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >new</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >DirectoryInfo</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >(imgFolder);<br /><span style=""> </span>dlstImages.DataSource = dir.GetFiles();<br /><span style=""> </span>dlstImages.DataBind();<br /><span style=""> </span>}</span></p></pre>Then I created the WriteXml method to perform two functions:<br /><ol><li>If the xml file (Adlist.xml) does not exist, create the xml with the details of the image submitted via the form.</li><li>If the xml file does exist, insert the details of the submitted image maintaining the correct nesting and formatting.</li></ol>The example in the book created the file by loading in the raw xml content. I thought that it was better to create the file programmatically. One gotcha I came across was having to use the absolute path for the xml file loaded by<span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" > XmlTextWriter</span> and <span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlDocument</span><span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >.Load</span></span>.<br /><br /><pre><p class="MsoNormal" style=""><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >protected</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >void</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > WriteXml()<br /><span style=""> </span>{<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >if</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > (!imageIsAd) </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >return</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >;<br /><br /> System.Drawing.</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >Image</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > UppedImage = System.Drawing.</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >Image</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >.FromStream(imageUpload.PostedFile.InputStream);<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >float</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > UploadedImageWidth = UppedImage.PhysicalDimension.Width;<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >float</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > UploadedImageHeight = UppedImage.PhysicalDimension.Height;<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > imagePath = </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"~/Assets/Ads/"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > + imageUpload.FileName;<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > xmlFile = </span><span style="background: black none repeat scroll 0% 0%; color: rgb(163, 21, 21); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >@"Absolute Path to AdList.xml"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >;<span style=""><br /></span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" > var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > xmlFileInfo = </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >new</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >FileInfo</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >(xmlFile);<span style=""><br /></span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >if</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > (!xmlFileInfo.Exists)<br /><span style=""> </span>{<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > writer = </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >new</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlTextWriter</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >(xmlFile, </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >null</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartDocument();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Advertisements"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Ad"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"ImageUrl"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteString(imagePath);<br /><span style=""> </span>writer.WriteEndElement();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Width"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteString(UploadedImageWidth.ToString());<br /><span style=""> </span>writer.WriteEndElement();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Height"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteString(UploadedImageHeight.ToString());<br /><span style=""> </span>writer.WriteEndElement();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"NavigateUrl"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteString(ImageLink.Text);<br /><span style=""> </span>writer.WriteEndElement();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteStartElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"AlternateText"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >, </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >""</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteString(AltText.Text);<br /><span style=""> </span>writer.WriteEndElement();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteEndElement();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteEndElement();<br /><span style=""> </span>writer.WriteRaw(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"\n"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>writer.WriteEndDocument();<br /><span style=""> </span>writer.Close();<br /><span style=""> </span>}<o:p> </o:p></span></p><p class="MsoNormal"><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >else<br /></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" ><span style=""> </span>{<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > xdoc = </span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >new</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > </span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlDocument</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >();<br /><span style=""> </span>xdoc.Load(xmlFile);<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; color: rgb(255, 128, 0); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;" >var</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > adverts = xdoc.SelectSingleNode(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Advertisements"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<o:p><br /></o:p><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlElement</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > ad = xdoc.CreateElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Ad"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlElement</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > img = xdoc.CreateElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"ImageUrl"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>img.InnerText = imagePath;<br /><span style=""> </span><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlElement</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > width = xdoc.CreateElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Width"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>width.InnerText = UploadedImageWidth.ToString();<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlElement</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > height = xdoc.CreateElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"Height"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>height.InnerText = UploadedImageHeight.ToString();<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlElement</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > navUrl = xdoc.CreateElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"NavigateUrl"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>navUrl.InnerText = ImageLink.Text;<br /><span style=""> </span></span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:yellow;" >XmlElement</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" > xaltText = xdoc.CreateElement(</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:lime;" >"AlternateText"</span><span style="background: black none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:100%;color:white;" >);<br /><span style=""> </span>xaltText.InnerText = AltText.Text;<o:p><br /></o:p><span style=""> </span>adverts.AppendChild(ad);<br /><span style=""> </span>ad.AppendChild(img);<br /><span style=""> </span>ad.AppendChild(width);<br /><span style=""> </span>ad.AppendChild(height);<br /><span style=""> </span>ad.AppendChild(navUrl);<br /><span style=""> </span>ad.AppendChild(xaltText);<br /><span style=""> </span>xdoc.Save(xmlFile);<br /><span style=""> </span>}<br /><span style=""> </span>}<br />}</span></p></pre>Next time I would think about breaking the WriteXml method out into a class and storing image details in an database rather than in an xml file on the file system.lynchjameshttp://www.blogger.com/profile/07275605071009490196noreply@blogger.com0