Advertisements

Learning .NET Framework interoperability by Example

Today we will discuss an example which uses .NET Framework interoperability to display headlines from the RSS feed of my site https://msdynamicsnavashwinitripathi.wordpress.com/

This example accesses classes in the System.XML assembly that is found in Global Assembly Cache.

Today’s example uses .NET Framework interoperability to display headlines from an RSS feed from my blog site, which has the following URL:

https://msdynamicsnavashwinitripathi.wordpress.com/feed/

We will use members of the System.XML assembly, which is part of the Microsoft .NET Framework class library and is installed in the global assembly cache.

Let’s start with creating a table to store the value of feeds as below:

DotNetInteroperability-1
Save your Table.

Next we will be creating a codeunit that has the following local variables:

DotNetInteroperability-2

Variable name DataType SubType
xml DotNet ‘System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.System.Xml.XmlDocument
items DotNet ‘System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.System.Xml.XmlNodeList
I Integer
title DotNet ‘System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.System.Xml.XmlNode
FeedTable Record DotNetInteroperability

After you create the codeunit, add a function LoadFeed and add below code to it:

 DotNetInteroperability-3
xml := xml.XmlDocument();

xml.Load(‘https://msdynamicsnavashwinitripathi.wordpress.com/feed/?format=xml’);

items := xml.SelectNodes(‘/rss/channel/item’);

FOR i := 0 TO items.Count – 1 DOBEGIN

title := items.Item(i).SelectSingleNode(‘title/text()’);

FeedTable.INIT;    FeedTable.”Topic ID” := i + 1;

FeedTable.”Topic Description” := title.Value;

IF NOT FeedTable.INSERT THEN

FeedTable.MODIFY;

END;

MESSAGE(‘Loading of Feeds Done.’);

Save your codeunit.

To see the example in the Microsoft Dynamics NAV Windows client, you will now create an action on a page that opens the codeunit.

Create a Page as below:

DotNetInteroperability-4
Create below Variable of codeunit created above:

DotNetInteroperability-5
Create below Page Actions:

DotNetInteroperability-6
Write a code for Load Feed Action as:

DotNetInteroperability.LoadFeed;

Save your Page.

Now Run this Page:

DotNetInteroperability-7
Click the Action Load Feed created above.

DotNetInteroperability-8
Respond OK to see the feeds loaded. Make sure your internet connection is operational as it directly fetch the Live feed from Internet.

DotNetInteroperability-9
In this case it will Load 50 Posts headings as this feed provides 50 as output, different feeds may return different numbers mostly 10-20 posts.

Using above logic you can create any such functionality and add value to your customers.

Thanks for going through this post, hopefully you may have earned some fruitful Tips.

You can follow the blog or subscribe to the RSS feed to remain updated and keep getting such posts in future.

Your response to my posts will keep motivating me for helping the community.

Advertisements

Important

Most of the contents you find in this blog will be either inherited from MSDN or Navision Developer IT Pro Help. Some places images are also directly taken from these sites. Purpose is simple to try those stuffs and re-produce adding few things as per my understanding to make easy understanding for others and quick reference.

Here nothing under my own brand or authorship of the content. At any point of time we are just promoting Microsoft stuffs nothing personnel with same.

Hope stuffs used here will not violate any copyright agreement with them. In case by mistake or in-intestinally it happens and the Microsoft feels these should not be used Microsoft have full right to inform me about same and will be glad to take down any such content which may be violating the norms.

Purpose is to promote Navision and share with community.

FB Profile

Like FB Page

%d bloggers like this: