<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechBlog &#187; .NET</title>
	<atom:link href="http://techblog.byllemos.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.byllemos.com</link>
	<description>Accelerating into the Future with Wisdom about Technology! Ingrid Byllemos</description>
	<lastBuildDate>Tue, 05 Jan 2010 00:04:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>RSS Reader Add-In for the RoleTailored Client</title>
		<link>http://techblog.byllemos.com/2009/10/rss-reader-add-in/</link>
		<comments>http://techblog.byllemos.com/2009/10/rss-reader-add-in/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 20:36:27 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[2009]]></category>
		<category><![CDATA[Add-Ins]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[RoleTailored Client]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[RTC]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=467</guid>
		<description><![CDATA[<p>Add-Ins are used to add new features to the RoleTailored Client and was introduced with NAV 2009 SP1.</p>
<p>I have previous written about a ASP.NET RSS reader &#8211; in that article, the collection of feeds was a C# function, so&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Add-Ins are used to add new features to the RoleTailored Client and was introduced with NAV 2009 SP1.</p>
<p>I have previous written about a ASP.NET RSS reader &#8211; in that article, the collection of feeds was a C# function, so why not use this function to extend the RoleTailored Client.</p>
<p>I will be using Visual Studio 2008 to write a Dynamic Link Library (dll), but you can also use the free Express version of Visual C#.</p>
<p>Let&#8217;s start by creating a new project &#8211; a class library. I have chosen to call it naviRSS.<br />
<span id="more-467"></span><br />
Add-In libraries must be strong signed, therefor go into properties -&gt; Signing. Here we are going to create a new key.</p>
<ul>
<li>Mark Sign the assemply</li>
<li>Chose to create a new strong key</li>
<li>Fill the Key file name
<ul>
<ol>
<img class="aligncenter size-full wp-image-470" title="naviRss-StrongKey" src="http://techblog.byllemos.com/wp-content/naviRss-StrongKey.JPG" alt="naviRss-StrongKey" width="70%" height="70%" /></ol>
</ul>
</li>
</ul>
<p>Now the signing page should look something like this:</p>
<p><img class="aligncenter size-full wp-image-468" title="naviRSS-Signing" src="http://techblog.byllemos.com/wp-content/naviRSS-Signing.JPG" alt="naviRSS-Signing" width="95%" height="95%" /></p>
<p>We have now signed the project, so next is to add the needed references to the project. Add the following references:</p>
<ul>
<li>System.Windows.Forms</li>
<li>System.Drawing</li>
<li>Microsoft.Dynamics.Framework.UI.Extensibility</li>
</ul>
<p>Microsoft.Dynamics.Framework.UI.Extensibility is a dll file that usually can be located here: C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client.</p>
<p>Finally we have the initial settings in place and are ready to handle the &#8220;real&#8221; code.</p>
<p>We will be using 3 items:</p>
<ul>
<li>RssControl.cs</li>
<li>RssFeeds.html</li>
<li>RssFeeds.cs</li>
</ul>
<p>Rename the default class1.cs to RssControl.cs (or delete it and create a new one <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</p>
<p>The RssControl will be containing the following functions:</p>
<ul>
<li>public RssControl(string template)
<ul>
<li>is the constructor to handle the integration with RSS Feeds</li>
</ul>
</li>
<li>void RssControl_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
<ul>
<li>what should happend when the html document is loaded</li>
</ul>
</li>
<li>public override string Text
<ul>
<li>updates some variables in the html document</li>
</ul>
</li>
<li>private string GetParameter(string parm, string defaultvalue)
<ul>
<li>gets the paramenters which are set from navision</li>
</ul>
</li>
<li>private string GetFeed(string rssURL, int maxItems, int showDesc)
<ul>
<li>is the GetFeed functions, that already is known from a earlier article</li>
</ul>
</li>
</ul>
<p>The complete RssControl.cs will look like this:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Dynamics.Framework.UI.Extensibility;
using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
&nbsp;
&nbsp;
namespace naviRss
<span class="br0">&#123;</span>
&nbsp;
    public class RssControl : WebBrowser
    <span class="br0">&#123;</span>
        private string template;
        private string text;
        private string html = &quot;&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;&quot;;
&nbsp;
        public RssControl<span class="br0">&#40;</span>string template<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            this.template = template;
            this.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler<span class="br0">&#40;</span>RssControl_DocumentCompleted<span class="br0">&#41;</span>;
        <span class="br0">&#125;</span>
&nbsp;
        void RssControl_DocumentCompleted<span class="br0">&#40;</span>object sender, WebBrowserDocumentCompletedEventArgs e<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            if <span class="br0">&#40;</span>this.DocumentText != this.html<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                this.DocumentText = this.html;
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
&nbsp;
        public override string Text
        <span class="br0">&#123;</span>
            get
            <span class="br0">&#123;</span>
                return text;
            <span class="br0">&#125;</span>
            set
            <span class="br0">&#123;</span>
                if <span class="br0">&#40;</span>text != value<span class="br0">&#41;</span>
                <span class="br0">&#123;</span>
                    text = value;
                    if <span class="br0">&#40;</span>string.IsNullOrEmpty<span class="br0">&#40;</span>value<span class="br0">&#41;</span><span class="br0">&#41;</span>
                    <span class="br0">&#123;</span>
                        html = &quot;&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;&quot;;
                    <span class="br0">&#125;</span>
                    else
                    <span class="br0">&#123;</span>
                        string rss_url = GetParameter<span class="br0">&#40;</span>&quot;rss_url&quot;, &quot;0&quot;<span class="br0">&#41;</span>;
&nbsp;
                        Int16 no_feeds = <span style="">0</span>;
                        Int16.TryParse<span class="br0">&#40;</span>GetParameter<span class="br0">&#40;</span>&quot;no_feeds&quot;, &quot;0&quot;<span class="br0">&#41;</span>, out no_feeds<span class="br0">&#41;</span>;
&nbsp;
                        string show_desc = GetParameter<span class="br0">&#40;</span>&quot;show_description&quot;, &quot;1&quot;<span class="br0">&#41;</span>;
&nbsp;
                        string feeds = &quot;&quot;;
                        if <span class="br0">&#40;</span>show_desc == &quot;true&quot; || show_desc == &quot;1&quot;<span class="br0">&#41;</span>
                            feeds = GetFeed<span class="br0">&#40;</span>rss_url, no_feeds, 1<span class="br0">&#41;</span>;
                        else
                            feeds = GetFeed<span class="br0">&#40;</span>rss_url, no_feeds, 0<span class="br0">&#41;</span>;
&nbsp;
                        html = this.template;
                        html = html.Replace<span class="br0">&#40;</span>&quot;%rss_url%&quot;, rss_url<span class="br0">&#41;</span>;
                        html = html.Replace<span class="br0">&#40;</span>&quot;%no_feeds%&quot;, no_feeds.ToString<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
                        html = html.Replace<span class="br0">&#40;</span>&quot;%show_description%&quot;, show_desc<span class="br0">&#41;</span>;
                        html = html.Replace<span class="br0">&#40;</span>&quot;%feeds%&quot;, feeds<span class="br0">&#41;</span>;
                    <span class="br0">&#125;</span>
                    this.DocumentText = html;
                <span class="br0">&#125;</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
&nbsp;
        private string GetParameter<span class="br0">&#40;</span>string parm, string defaultvalue<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            foreach <span class="br0">&#40;</span>string parameter in text.Split<span class="br0">&#40;</span>'¤'<span class="br0">&#41;</span><span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                if <span class="br0">&#40;</span>parameter.StartsWith<span class="br0">&#40;</span>parm + &quot;=&quot;<span class="br0">&#41;</span><span class="br0">&#41;</span>
                <span class="br0">&#123;</span>
                    return parameter.Substring<span class="br0">&#40;</span>parm.Length + 1<span class="br0">&#41;</span>;
                <span class="br0">&#125;</span>
            <span class="br0">&#125;</span>
            return defaultvalue;
        <span class="br0">&#125;</span>
&nbsp;
        private string GetFeed<span class="br0">&#40;</span>string rssURL, int maxItems, int showDesc<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            string FeedsCollected = &quot;&quot;;
&nbsp;
            System.Net.WebRequest myRequest = System.Net.WebRequest.Create<span class="br0">&#40;</span>rssURL<span class="br0">&#41;</span>;
            System.Net.WebResponse myResponse = myRequest.GetResponse<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp;
            System.IO.Stream rssStream = myResponse.GetResponseStream<span class="br0">&#40;</span><span class="br0">&#41;</span>;
            System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument<span class="br0">&#40;</span><span class="br0">&#41;</span>;
            rssDoc.Load<span class="br0">&#40;</span>rssStream<span class="br0">&#41;</span>;
&nbsp;
            System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes<span class="br0">&#40;</span>&quot;rss/channel/item&quot;<span class="br0">&#41;</span>;
&nbsp;
            string title = &quot;&quot;;
            string link = &quot;&quot;;
            string pub_date = &quot;&quot;;
            string desc = &quot;&quot;;
&nbsp;
            if <span class="br0">&#40;</span>maxItems == 0<span class="br0">&#41;</span>
                maxItems = rssItems.Count;
&nbsp;
            if <span class="br0">&#40;</span><span class="br0">&#40;</span>maxItems &gt; 0<span class="br0">&#41;</span> &amp;&amp; <span class="br0">&#40;</span>rssItems.Count &lt; maxItems<span class="br0">&#41;</span><span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                maxItems = rssItems.Count;
            <span class="br0">&#125;</span>
&nbsp;
            for <span class="br0">&#40;</span>int i = <span style="">0</span>; i &lt; maxItems; i++<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                title = rssItems.Item<span class="br0">&#40;</span>i<span class="br0">&#41;</span>.SelectSingleNode<span class="br0">&#40;</span>&quot;title&quot;<span class="br0">&#41;</span>.InnerText;
                link = rssItems.Item<span class="br0">&#40;</span>i<span class="br0">&#41;</span>.SelectSingleNode<span class="br0">&#40;</span>&quot;link&quot;<span class="br0">&#41;</span>.InnerText;
                pub_date = rssItems.Item<span class="br0">&#40;</span>i<span class="br0">&#41;</span>.SelectSingleNode<span class="br0">&#40;</span>&quot;pubDate&quot;<span class="br0">&#41;</span>.InnerText;
                desc = rssItems.Item<span class="br0">&#40;</span>i<span class="br0">&#41;</span>.SelectSingleNode<span class="br0">&#40;</span>&quot;description&quot;<span class="br0">&#41;</span>.InnerText;
&nbsp;
                FeedsCollected += &quot;&lt;a href='&quot; + link + &quot;' target='new'&gt;&quot; + title + &quot;&lt;/a&gt;&lt;br/&gt;&quot;;
&nbsp;
            <span class="br0">&#125;</span>
&nbsp;
            return FeedsCollected;
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
&nbsp;
<span class="br0">&#125;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>Ok &#8211; now we have all the info we need about the feeds. Next is to create a html page, which we will be using to present the feeds with. Add a new item RssFeeds.html to the project.</p>
<p>It is a pretty simple page and could look like this:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML <span style="">4.0</span> Transitional//EN&quot;&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;&lt;/title&gt;
	&lt;/head&gt;
&nbsp;
	&lt;body&gt;
        	%feeds%
	&lt;/body&gt;
&lt;/html&gt;</div></pre><!--END_DEVFMTCODE--></p>
<p>Notice that we have a variable %feeds%. This variable will be updated by the function Text, that is located in the RssControl.cs.
<p />
<p>To be able to use the html page from the RoleTailored Client, we have to embed the file. This is done by adding the resource file Resources.resx to the project.</p>
<p>Then afterwards open Resources.resx and drop (drag &#038; drop) the RssFeeds.html file on it.
<p />
<p>Now all we need is to add the item RssFeeds.cs to the project (new item -> class). In RssFeeds.cs we will be handling CreateControl and AllowCaptionControl.</p>
<p>When the NAV Client needs to create the actual winforms control, it will be calling the CreateControl. By having our own CreateControl in the RssFeeds.cs &#8211; we are overriding the default method and giving it a html template instead.</p>
<p>AllowCaptionControl is used the override the default handling of captions.</p>
<p>RssFeeds.cs will look like this:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Microsoft.Dynamics.Framework.UI.Extensibility;
using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
using System.Windows.Forms;
&nbsp;
namespace naviRss
<span class="br0">&#123;</span>
&nbsp;
    <span class="br0">&#91;</span>ControlAddInExport<span class="br0">&#40;</span>&quot;naviRss&quot;<span class="br0">&#41;</span><span class="br0">&#93;</span>
    public class RssFeeds : StringControlAddInBase, IStringControlAddInDefinition
    <span class="br0">&#123;</span>
        protected override Control CreateControl<span class="br0">&#40;</span><span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            //System.Diagnostics.Debugger.Launch<span class="br0">&#40;</span><span class="br0">&#41;</span>;
            var RssWeb = new RssControl<span class="br0">&#40;</span>Resources.RssFeeds<span class="br0">&#41;</span>;
&nbsp;
            RssWeb.MinimumSize = new Size<span class="br0">&#40;</span>600, 200<span class="br0">&#41;</span>;
            RssWeb.MaximumSize = new Size<span class="br0">&#40;</span>600, 200<span class="br0">&#41;</span>;
            RssWeb.ScrollBarsEnabled = false;
            RssWeb.ScriptErrorsSuppressed = true;
            RssWeb.WebBrowserShortcutsEnabled = false;
&nbsp;
            return RssWeb;
        <span class="br0">&#125;</span>
&nbsp;
        public override bool AllowCaptionControl
        <span class="br0">&#123;</span>
            get
            <span class="br0">&#123;</span>
                return false;
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>
[ControlAddInExport("naviRss")] is used to set the &#8220;control name&#8221; for navision. In this case the Control will be known as naviRss.</p>
<p>
Everything is now in place and we are ready to build our project.
</p>
<p>
Build the project and place the naviRss.dll in the Add-Ins directory under the RoleTailored Client.
</p>
<p>
A little tip &#8211; if you don&#8217;t want to copy the dll yourself into the Add-Ins directory, then add the following commandline to post-build event commandline in the  project properties under &#8220;build events&#8221;:  </p>
<p>copy naviRss.dll &#8220;C:\Program Files\Microsoft Dynamics NAV\60\RoleTailored Client\Add-ins&#8221;
</p>
<p>
All you know have to do is setting up the dll in navision and build a page to use it. This will be described in the next article.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2009/10/rss-reader-add-in/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Building a RSS reader in ASP.Net</title>
		<link>http://techblog.byllemos.com/2009/10/building-a-rss-reader-in-asp-net/</link>
		<comments>http://techblog.byllemos.com/2009/10/building-a-rss-reader-in-asp-net/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 14:52:03 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=453</guid>
		<description><![CDATA[<p>Hi</p>
<p>RSS Feeds are just XMLs &#8211; so building a RSS reader is not so difficult, first you know how to do it <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Let&#8217;s start with looking at C# function that reads the RSS&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Hi</p>
<p>RSS Feeds are just XMLs &#8211; so building a RSS reader is not so difficult, first you know how to do it <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Let&#8217;s start with looking at C# function that reads the RSS Feeds.</p>
<p>First step is to collect the feeds. This is done by using WebRequest:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">System.Net.WebRequest myRequest = System.Net.WebRequest.Create<span class="br0">&#40;</span>rssURL<span class="br0">&#41;</span>;
System.Net.WebResponse myResponse = myRequest.GetResponse<span class="br0">&#40;</span><span class="br0">&#41;</span>;
&nbsp;
System.IO.Stream rssStream = myResponse.GetResponseStream<span class="br0">&#40;</span><span class="br0">&#41;</span>;
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument<span class="br0">&#40;</span><span class="br0">&#41;</span>;
rssDoc.Load<span class="br0">&#40;</span>rssStream<span class="br0">&#41;</span>;
</div></pre><!--END_DEVFMTCODE--><span id="more-453"></span></p>
<p>Now that we have collected the feeds, we are able to process the XML (rssDoc).  In my example I would like to run though the items and then write the title.</p>
<p>This would look something like this:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes<span class="br0">&#40;</span>&quot;rss/channel/item&quot;<span class="br0">&#41;</span>;
&nbsp;
string title = &quot;&quot;;
string link = &quot;&quot;;
&nbsp;
for <span class="br0">&#40;</span>int i = <span style="">0</span>; i &lt; rssItems.Count; i++<span class="br0">&#41;</span>
<span class="br0">&#123;</span>            
    title    = rssItems.Item<span class="br0">&#40;</span>i<span class="br0">&#41;</span>.SelectSingleNode<span class="br0">&#40;</span>&quot;title&quot;<span class="br0">&#41;</span>.InnerText;
    link     = rssItems.Item<span class="br0">&#40;</span>i<span class="br0">&#41;</span>.SelectSingleNode<span class="br0">&#40;</span>&quot;link&quot;<span class="br0">&#41;</span>.InnerText;            
&nbsp;
    Response.Write<span class="br0">&#40;</span>&quot;&lt;p&gt;&lt;a href='&quot; + link + &quot;' target='new'&gt;&quot; + title + &quot;&lt;/a&gt;&lt;br/&gt;&quot;<span class="br0">&#41;</span>;
&nbsp;
    Response.Write<span class="br0">&#40;</span>&quot;&lt;/p&gt;&quot;<span class="br0">&#41;</span>;
<span class="br0">&#125;</span></div></pre><!--END_DEVFMTCODE--><br />
That&#8217;s all, now you have a function that can collect the Feeds.<br />
<br />
Please Notice &#8211; not all Feeds have the same XML format. They can/will differ from Feed provider to Feed provider.<br />
<br />
Now lets take a closer look on the ASP.Net page.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">&lt;%@ Page Language=&quot;C#&quot; %&gt;
&nbsp;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&nbsp;
&lt;script runat=&quot;server&quot;&gt;
    public void GetFeed<span class="br0">&#40;</span>string rssURL<span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
	//Put here the code descriped ealier in this section
    <span class="br0">&#125;</span>
&lt;/script&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;mibuso Feeds&lt;/title&gt;    
&lt;/head&gt;
&lt;body style =&quot;font-family: Tahoma,Arial,Verdana,Helvetica;&quot;&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
        &lt;div&gt;        
            &lt;%                
                rssUrl = &quot;http://www.mibuso.com/forum/smartfeed.php?forum=23&amp;firstpostonly=1&amp;limit=NO_LIMIT&amp;count_limit=10&amp;sort_by=postdate_desc&amp;feed_type=RSS2.0&amp;feed_style=HTML&quot;;
&nbsp;
                Response.Write<span class="br0">&#40;</span>&quot;mibuso Feeds&lt;br /&gt;&quot;<span class="br0">&#41;</span>;
                GetFeed<span class="br0">&#40;</span>rssUrl<span class="br0">&#41;</span>;
            %&gt;
        &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</div></pre><!--END_DEVFMTCODE--><br />
Here we assume, that the above C# function is called GetFeed. This function must be added in a script section and can afterwards be called from the body section.<br />
<br />
Next you place the asp.net page on the internet server. When calling it &#8211; you should get a result like this:<br />
<img src="http://techblog.byllemos.com/wp-content/RssFeeds-AspNet.jpg" alt="RssFeeds-AspNet" title="RssFeeds-AspNet" width="90%" height="90%" class="aligncenter size-full wp-image-457" /><br />
<br />
That&#8217;s all, now you have a ASP.Net page, that collects the feeds and show the title.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2009/10/building-a-rss-reader-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expanding the FTP automation</title>
		<link>http://techblog.byllemos.com/2009/03/expanding-the-ftp-automation/</link>
		<comments>http://techblog.byllemos.com/2009/03/expanding-the-ftp-automation/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 22:14:43 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Navision]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=134</guid>
		<description><![CDATA[<p>In the previous post I have started the development of FTP automation. The first post did only include some basic functions such as download, upload and list. Now it’s time for some more functionality.</p>
<p>So now let us add the&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>In the previous post I have started the development of FTP automation. The first post did only include some basic functions such as download, upload and list. Now it’s time for some more functionality.</p>
<p>So now let us add the possibility to delete and rename files.</p>
<p>Deleting a file from the FTP server is actually pretty simple. All you have to know is the filename and where it is place. Once you have this information you can use the WebRequestMethods to delete the file.<br />
<span id="more-134"></span><br />
We will start with making a connection to the FTP Server:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li> string ConnectionString = &quot;ftp://&quot; + strFTPServer + ':' + intFTPPort + &quot;/&quot; + strFtpDirectory + @FileName;</li><li>&nbsp;</li><li>FtpWebRequest FtpRequest = <span class="br0">&#40;</span>FtpWebRequest<span class="br0">&#41;</span>FtpWebRequest.Create<span class="br0">&#40;</span>ConnectionString<span class="br0">&#41;</span>;</li><li>FtpRequest.Credentials = new NetworkCredential<span class="br0">&#40;</span>strUsername, strPassword<span class="br0">&#41;</span>;</li><li>FtpRequest.KeepAlive = false;</li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Now we are ready to delete the file:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li>FtpRequest.Method = WebRequestMethods.Ftp.DeleteFile;</li><li>FtpRequest.GetResponse<span class="br0">&#40;</span><span class="br0">&#41;</span>.Close<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>This is done by using WebRequestMethods to set the DeleteFile Method and then afterwards executing the deletion with GetResponse.</p>
<p>Remember to catch Execeptions, to see if the deletion went well.</p>
<p>So now you can delete files from the FTP server. </p>
<p>This was easy. So let us continue with the renaming.</p>
<p>Renaming a file is similar to the deletion of a file. Again all you need to know is the filename &#038; path and then you can use WebRequestMethods to rename the file.</p>
<p>As in the deletion of a file you will start with making the server connection:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li>string ConnectionString = &quot;ftp://&quot; + strFTPServer + ':' + intFTPPort + &quot;/&quot; + strFtpDirectory + @FileName;</li><li>&nbsp;</li><li>FtpWebRequest FtpRequest = <span class="br0">&#40;</span>FtpWebRequest<span class="br0">&#41;</span>FtpWebRequest.Create<span class="br0">&#40;</span>ConnectionString<span class="br0">&#41;</span>;</li><li>FtpRequest.Credentials = new NetworkCredential<span class="br0">&#40;</span>strUsername, strPassword<span class="br0">&#41;</span>;</li><li>FtpRequest.KeepAlive = false;</li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Now that the server connection is in place &#8211; you are ready to perform the renaming:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow"><ol><li></li><li>FtpRequest.Method = WebRequestMethods.Ftp.Rename;</li><li>FtpRequest.RenameTo = NewFileName;</li><li>FtpRequest.GetResponse<span class="br0">&#40;</span><span class="br0">&#41;</span>.Close<span class="br0">&#40;</span><span class="br0">&#41;</span>;</li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>As you can see, we are also here using WebRequestMethods to set Rename Method. First the Method is chosen; you set the new filename with FtpRequest.RenameTo and then afterwards execute the rename with GetResponse.</p>
<p>So the only difference to the deletion is the Method and the RenameTo command. </p>
<p>That’s all folks! Now you can delete and rename files on an Ftp.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2009/03/expanding-the-ftp-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a FTP automation</title>
		<link>http://techblog.byllemos.com/2008/12/writing-a-ftp-automation/</link>
		<comments>http://techblog.byllemos.com/2008/12/writing-a-ftp-automation/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 22:25:36 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Navision]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=115</guid>
		<description><![CDATA[<p>Over some time I have been using a plain dos ftp from Navision. There is some advantages and some disadvantage combined with it. </p>
<p>A advantage is, that this use does not require any third part products; but a disadvantage&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Over some time I have been using a plain dos ftp from Navision. There is some advantages and some disadvantage combined with it. </p>
<p>A advantage is, that this use does not require any third part products; but a disadvantage is that you does not have the fully control over the file transfer, so you have to build your own kind of file log and parsing it to know if everything went well.</p>
<p>Therefor I decided to build my own automation for Navision in c#.<br />
<span id="more-115"></span><br />
My first version of the automation should only contain some basic functions.<br />
Which are:<br />
- Upload File<br />
- Download File<br />
- List</p>
<p>To upload a file we will be using FTPWebRequest, which is a part of System.Net and FileInfo,<br />
which is a part of System.IO.</p>
<p>We will start with making a connection to the FTP Server:</p>
<blockquote><p>string ConnectionString =<br />
<font class="blankspace">&#8230;&#8230;</font>&#8220;ftp://&#8221; + strFTPServer + &#8216;:&#8217; +intFTPPort + &#8220;/&#8221; +strFtpDirectory +FileName;</p>
<p>FtpWebRequest FtpRequest =<br />
<font class="blankspace">&#8230;&#8230;</font>(FtpWebRequest)FtpWebRequest.Create(new Uri(ConnectionString));</p>
<p>FtpRequest.Credentials = new NetworkCredential(strUsername, strPassword);
</p></blockquote>
<p>If the connection went well, we are ready for to upload the file. The upload is done by<br />
creating a File Stream and then writing the file byte by byte to the Ftp Server.</p>
<blockquote><p>
FtpRequest.Method = WebRequestMethods.Ftp.UploadFile;<br />
FtpRequest.ContentLength = FileInf.Length;</p>
<p>FileInfo FileInf = new FileInfo(FileName);</p>
<p>int BufferLength = 2048;<br />
byte[] Buffer = new byte[BufferLength];<br />
int ContentLength;</p>
<p>FileStream UpStream = FileInf.OpenRead();<br />
Stream FtpStream = FtpRequest.GetRequestStream();                   </p>
<p>ContentLength = UpStream.Read(Buffer, 0, BufferLength);<br />
while (ContentLength != 0)<br />
{<br />
<font class="blankspace">&#8230;&#8230;</font>FtpStream.Write(Buffer, 0, ContentLength);<br />
<font class="blankspace">&#8230;&#8230;</font>ContentLength = UpStream.Read(Buffer, 0, BufferLength);<br />
}</p>
<p>FtpStream.Close();<br />
FtpStream.Dispose();</p>
<p>UpStream.Close();<br />
UpStream.Dispose();
</p></blockquote>
<p>To download a file is pretty similar to upload a file.</p>
<p>First we start with making a connection to the Server:</p>
<blockquote><p>
FtpWebRequest FtpRequest =<br />
<font class="blankspace">&#8230;&#8230;</font>(FtpWebRequest)FtpWebRequest.Create(new Uri(ConnectionString));</p>
<p>FtpRequest.Credentials = new NetworkCredential(strUsername, strPassword);
</p></blockquote>
<p>and then we downloads the file by using a stream:</p>
<blockquote><p>
System.IO.Stream ResponseStream = null;<br />
System.IO.FileStream DownStream = null;</p>
<p>FtpRequest.Method = WebRequestMethods.Ftp.DownloadFile;<br />
FtpWebResponse WebResponse = (FtpWebResponse)FtpRequest.GetResponse();<br />
ResponseStream = WebResponse.GetResponseStream();<br />
DownStream = System.IO.File.Open(DownFileName + &#8220;.tmp&#8221;, System.IO.FileMode.Create);</p>
<p>while (((iWork = ResponseStream.Read(buf, 0, buf.Length)) > 0))<br />
<font class="blankspace">&#8230;&#8230;</font>DownStream.Write(buf, 0, iWork);</p>
<p>ResponseStream.Close();<br />
ResponseStream.Dispose();</p>
<p>DownStream.Flush();
</p></blockquote>
<p>If you want to check that the download went well &#8211; you can always check the return response<br />
from the FtpRequest:</p>
<blockquote><p>
FtpWebResponse ReturnResponse = ((FtpWebResponse)FtpRequest.GetResponse());<br />
if (StatusOk(ReturnResponse))<br />
{<br />
<font class="blankspace">&#8230;&#8230;</font>DownloadSucceeded = true;<br />
}
</p></blockquote>
<p>And then finally the List functionality. This function will be useful when downloading files.</p>
<p>Again we start with making a connection to the Server:</p>
<blockquote><p>
FtpWebRequest FtpRequest =<br />
<font class="blankspace">&#8230;&#8230;</font>(FtpWebRequest)FtpWebRequest.Create(new Uri(ConnectionString));</p>
<p>FtpRequest.Credentials = new NetworkCredential(strUsername, strPassword);
</p></blockquote>
<p>Then we use the ListDirectoryDetails funtion to find the files.</p>
<blockquote><p>
FtpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;<br />
FtpWebResponse Response = (FtpWebResponse)FtpRequest.GetResponse();
</p></blockquote>
<p>As you can see, where are again using the stream functionality.</p>
<blockquote><p>
StringBuilder Result = new StringBuilder();<br />
StreamReader Reader = new StreamReader(Response.GetResponseStream());<br />
string Line = Reader.ReadLine();<br />
string tmpLine;<br />
while (Line != null)<br />
{<br />
<font class="blankspace">&#8230;&#8230;</font>tmpLine = Line;</p>
<p><font class="blankspace">&#8230;&#8230;</font>//Lines starting with d is directories &#8211; everything else is file<br />
<font class="blankspace">&#8230;&#8230;</font>if (!tmpLine.StartsWith(&#8220;d&#8221;))<br />
<font class="blankspace">&#8230;&#8230;</font>{<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>tmpLine = Line.Substring(Line.LastIndexOf(&#8216; &#8216;) + 1);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Result.Append(tmpLine);<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>Result.Append(&#8220;\n&#8221;);<br />
<font class="blankspace">&#8230;&#8230;</font>}<br />
<font class="blankspace">&#8230;&#8230;</font>Line = Reader.ReadLine();<br />
}</p>
<p>Reader.Close();<br />
Response.Close();</p>
<p>string[] FileList<br />
FileList = Result.ToString().Split(&#8216;\n&#8217;);
</p></blockquote>
<p>Thats all – now you can upload, download and list files.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/12/writing-a-ftp-automation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Writing an automation for Navision in C#</title>
		<link>http://techblog.byllemos.com/2008/10/writing-an-automation-for-navision-in-c/</link>
		<comments>http://techblog.byllemos.com/2008/10/writing-an-automation-for-navision-in-c/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 20:12:57 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ADO]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Navision]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=74</guid>
		<description><![CDATA[<p>Writing a automation for Navision is pretty simple, when you first know how to do it <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>First of all, I assume that you already know about C#.</p>
<p>So here are the basic steps for&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Writing a automation for Navision is pretty simple, when you first know how to do it <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>First of all, I assume that you already know about C#.</p>
<p>So here are the basic steps for creating an automation:<br />
<span id="more-74"></span><br />
1. Create a new Class Library project.</p>
<ul>
<li>Chose File -&gt; New -&gt; Project and then chose Class Library and save it as myAutomation (or use you own name)</li>
</ul>
<p>2. Before making any changes &#8211; setup the Properties</p>
<ul>
<li>Chose Project -&gt; myAutomation Properties</li>
<li>Select tab Application and then the button Assembly Information
<ul>
<li>In the Assembly Information window, mark &#8220;Make assembly COM-Visible&#8221; and chose Ok</li>
</ul>
</li>
<li>Select tab Build
<ul>
<li>Mark &#8220;Register for COM interop&#8221;</li>
</ul>
</li>
<li>Select tab Signing
<ul>
<li>Mark &#8220;Sign the assembly&#8221; and create a key files (or chose an existing one)</li>
</ul>
</li>
</ul>
<p>Now everything is setup and you can close the property setup.</p>
<p>3. Add the namespace for InteropServices
<ul>
<li>This is done by adding using System.Runtime.InteropServices</li>
</ul>
<p>You should now have a code similar to the following:</p>
<blockquote><p>using System;<br />
using System.Text;<br />
using System.Runtime.InteropServices;</p>
<p>namespace myAutomation<br />
{<br />
<font class="blankspace">&#8230;&#8230;</font>public class myAutomation<br />
<font class="blankspace">&#8230;&#8230;</font>{<br />
<font class="blankspace">&#8230;&#8230;</font>}<br />
}</p></blockquote>
<p>4. Declare the interface</p>
<p>First you have to decide if the class should be visible or not. In this case we want it to be visible, so that we can use it with the automation.</p>
<blockquote><p>[ComVisible(true)]</p></blockquote>
<p>Next you can choose to set the Guid and ProgId.</p>
<blockquote><p>[Guid("41E646B3-F65C-4d8e-8539-499FA56C7076")]<br />
[ProgId("myAutomation")]
</p></blockquote>
<p>Then decide the Class Interface Type. You can choose between None and Autodual.</p>
<blockquote><p>
[ClassInterface(ClassInterfaceType.AutoDual)]
</p></blockquote>
<p>For now we will be using Autodual, because None requires the use of Interface and class&#8217;es &#8211; where as Autodual only uses class.</p>
<p>You should now have a code similar to the following:</p>
<blockquote><p>using System;<br />
using System.Text;<br />
using System.Runtime.InteropServices;</p>
<p>namespace myAutomation<br />
{<br />
<font class="blankspace">&#8230;&#8230;</font>[ComVisible(true)]<br />
<font class="blankspace">&#8230;&#8230;</font>[Guid("41E646B3-F65C-4d8e-8539-499FA56C7076")]<br />
<font class="blankspace">&#8230;&#8230;</font>[ClassInterface(ClassInterfaceType.AutoDual)]<br />
<font class="blankspace">&#8230;&#8230;</font>[ProgId("myAutomation")]<br />
<font class="blankspace">&#8230;&#8230;</font>public class myAutomation<br />
<font class="blankspace">&#8230;&#8230;</font>{<br />
<font class="blankspace">&#8230;&#8230;</font>}<br />
}</p></blockquote>
<p>Now you can add all the functions that you need.</p>
<p>Notice, you can hide functions and classes from the automation by using Private or [ComVisible(false)]</p>
<p>Here is a code example for an automation with visible and invisible methods.</p>
<blockquote><p>
using System;<br />
using System.Text;<br />
using System.Runtime.InteropServices;</p>
<p>namespace myAutomation<br />
{<br />
<font class="blankspace">&#8230;&#8230;</font>[ComVisible(true)]<br />
<font class="blankspace">&#8230;&#8230;</font>[Guid("41E646B3-F65C-4d8e-8539-499FA56C7076")]<br />
<font class="blankspace">&#8230;&#8230;</font>[ClassInterface(ClassInterfaceType.AutoDual)]<br />
<font class="blankspace">&#8230;&#8230;</font>[ProgId("myAutomation")]<br />
<font class="blankspace">&#8230;&#8230;</font>public class myAutomation<br />
<font class="blankspace">&#8230;&#8230;</font>{<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>public Int16 Add(Int16 X, Int16 Y)<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>{<br />
<font class="blankspace">&#8230;&#8230;&#8230;&#8230;&#8230;.</font>Int16 Result = (Int16)(X + Y);<br />
<font class="blankspace">&#8230;&#8230;&#8230;&#8230;&#8230;.</font>return Result;<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>}</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>//Is hidden in the Automation because of Private<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>private Int16 PrivateAdd(Int16 X, Int16 Y)<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>{<br />
<font class="blankspace">&#8230;&#8230;&#8230;&#8230;&#8230;.</font>Int16 Result = (Int16)(X + Y);<br />
<font class="blankspace">&#8230;&#8230;&#8230;&#8230;&#8230;.</font>return Result;<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>}</p>
<p><font class="blankspace">&#8230;&#8230;&#8230;..</font>//Is hidden in the Automation because of ComVisible<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>[ComVisible(false)]<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>public Int16 InvisibleAdd(Int16 X, Int16 Y)<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>{<br />
<font class="blankspace">&#8230;&#8230;&#8230;&#8230;&#8230;.</font>Int16 Result = (Int16)(X + Y);<br />
<font class="blankspace">&#8230;&#8230;&#8230;&#8230;&#8230;.</font>return Result;<br />
<font class="blankspace">&#8230;&#8230;&#8230;..</font>}<br />
<font class="blankspace">&#8230;&#8230;</font>}<br />
}
</p></blockquote>
<p>Functions are in the automation presented as Methods, where as C# properties (public set; get;) are presented as properties.</p>
<p>Please note, that I am using Visual Studio C# 2008 (you can download the Express version from Microsoft <a href="http://www.microsoft.com/express/vcsharp/">here</a>.)</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/10/writing-an-automation-for-navision-in-c/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>C# and Dns.GetHostEntry</title>
		<link>http://techblog.byllemos.com/2008/10/c-and-dnsgethostentry/</link>
		<comments>http://techblog.byllemos.com/2008/10/c-and-dnsgethostentry/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 21:19:30 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Automations]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=73</guid>
		<description><![CDATA[<p>I am currently building a new FTP automation for Navision. </p>
<p>During this I discovered that Dns.GetHostEntry is not always stable.<br />
<span id="more-73"></span><br />
So I did some testing. Here are some of the results:</p>
<blockquote>
<table border="0">
<tbody>
<tr></tr></tbody></table></blockquote><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>I am currently building a new FTP automation for Navision. </p>
<p>During this I discovered that Dns.GetHostEntry is not always stable.<br />
<span id="more-73"></span><br />
So I did some testing. Here are some of the results:</p>
<blockquote>
<table border="0">
<tbody>
<tr>
<td>Dns.GetHostEntry(localhost)</td>
<td>Ok</td>
</tr>
<tr>
<td>Dns.GetHostEntry(127.0.0.1)</td>
<td>Ok</td>
</tr>
<tr>
<td>Dns.GetHostEntry(192.168.1.147)</td>
<td>No Such   Host is Known</td>
</tr>
</tbody>
</table>
</blockquote>
<p>The funny side is that its all to the same ftp server.</p>
<p>It seams, that Dns.GetHostEntry often throws the exception (No Such Host is Known).</p>
<p>So, what to do? Well I have chosen to use the command Dns.GetHostAddresses instead of Dns.GetHostEntry.</p>
<p>The difference between GetHostEntry and GetHostAddresses is that GetHostEntry will attempt a DNS reverse resolve before giving you the IP address back, where as GetHostAddress just returns the IP address.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/10/c-and-dnsgethostentry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

