Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / VS Tools for Office / March 2007

Tip: Looking for answers? Try searching our database.

Outlook & RSS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
elziko - 14 Mar 2007 15:55 GMT
Is there any way I can get notification of a new RRS item when it appears in
a folder - and to then get hold of all the information within that item?

At the moment I don;t seem to be even able to get a refernce to one of my
RSS folders - they don't seem to be normal Outlook.Folder objects.

TIA
Bryan Phillips - 15 Mar 2007 03:11 GMT
The RSS Feeds API is not actually a part of Outlook or IE, but you can
still access it via a type library.  Search MSDN for the "Feeds API".  
Let me know if you need more help than that.  I presented Microsoft's
DevCares on this topic last month.

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com

> Is there any way I can get notification of a new RRS item when it appears in
> a folder - and to then get hold of all the information within that item?
[quoted text clipped - 3 lines]
>
> TIA
elziko - 15 Mar 2007 17:37 GMT
> The RSS Feeds API is not actually a part of Outlook or IE, but you can
> still access it via a type library.  Search MSDN for the "Feeds API".
> Let me know if you need more help than that.  I presented Microsoft's
> DevCares on this topic last month.

Thanks very much! Do you know of any good samples that show RSS event
notifications in *managed* code?

TIA
Bryan Phillips - 17 Mar 2007 12:56 GMT
First add a reference to the Microsoft.Feeds COM component.

Then, use the code below:

Code for Form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Feeds.Interop;

namespace RSSViewer
{
   public partial class Form1 : Form
   {
       FeedsManager feedsManager = new FeedsManager();

       public Form1()
       {
           InitializeComponent();

       }

       private void Form1_Load(object sender, EventArgs e)
       {
           LoadFolders();
       }

       private void LoadFolders()
       {
           IFeedFolder root = feedsManager.RootFolder as IFeedFolder;

           IFeedFolderEvents_Event watcher =
root.GetWatcher(FEEDS_EVENTS_SCOPE.FES_ALL,
FEEDS_EVENTS_MASK.FEM_FOLDEREVENTS | FEEDS_EVENTS_MASK.FEM_FEEDEVENTS)
               as IFeedFolderEvents_Event;

           watcher.FeedAdded += new
IFeedFolderEvents_FeedAddedEventHandler(watcher_FeedManager);
           watcher.FeedDeleted += new
IFeedFolderEvents_FeedDeletedEventHandler(watcher_FeedManager);

           InitializeReader(root);
       }

       void watcher_FeedManager(string Path)
       {
           IFeedFolder root = feedsManager.RootFolder as IFeedFolder;
           InitializeReader(root);
       }

       private void InitializeReader(IFeedFolder root)
       {
           tvFolders.Nodes.Clear();
           TreeNode tn = new TreeNode("RSS Feeds");
           AddFeeds(tn, root);
           AddFolder(tn, root);
           tn.Tag = root;
           tvFolders.Nodes.Add(tn);
           tvFolders.ExpandAll();
       }

       private void AddFolder(TreeNode parent, IFeedFolder folder)
       {
           IFeedsEnum folders = folder.Subfolders as IFeedsEnum;
           for (int i = 0; i < folders.Count; i++)
           {
               IFeedFolder subFolder = folders.Item(i) as IFeedFolder;

               TreeNode tn = null;
               tn = new TreeNode(subFolder.Name);

               tn.Tag = subFolder;

               parent.Nodes.Add(tn);

               AddFeeds(tn, subFolder);

               AddFolder(tn, subFolder);
           }
       }

       private void AddFeeds(TreeNode parent, IFeedFolder folder)
       {
           IFeedsEnum feeds = folder.Feeds as IFeedsEnum;

           for (int i = 0; i < feeds.Count; i++)
           {
               IFeed feed = feeds.Item(i) as IFeed;
               try
               {
                   //feed.Download();
                   TreeNode tn = null;
                   System.Diagnostics.Debug.WriteLine("Feed: {0}",
feed.Name);
                   tn = new TreeNode(string.Format("{0}: {1}",
feed.Name, feed.Description));
                   tn.Tag = feed;
                   parent.Nodes.Add(tn);

               }
               catch (Exception)
               {
               }
           }
       }

       private void tvFolders_AfterSelect(object sender,
TreeViewEventArgs e)
       {
           lbFeeds.Items.Clear();
           TreeNode tn = e.Node;
           IFeed feed = tn.Tag as IFeed;

           if (feed == null)
               return;

           IFeedsEnum feeds = feed.Items  as IFeedsEnum;

           for (int i = 0; i < feeds.Count; i++)
           {
               IFeedItem item = feeds.Item(i) as IFeedItem;
               ListBoxFeedItemHelper feedItem = new
ListBoxFeedItemHelper(item);
               lbFeeds.Items.Add(feedItem);

           }
       }

       private void lbFeeds_SelectedIndexChanged(object sender,
EventArgs e)
       {
           ListBoxFeedItemHelper helper = lbFeeds.SelectedItem as
ListBoxFeedItemHelper;

           webBrowserFeedOuput.DocumentText = helper.Description;
       }

       private void refreshToolStripMenuItem_Click(object sender,
EventArgs e)
       {
           InitializeReader(feedsManager.RootFolder as IFeedFolder);
       }

   }

   class ListBoxFeedItemHelper
   {
       IFeedItem feedItem;
       public ListBoxFeedItemHelper(IFeedItem item)
       {
           feedItem = item;
       }

       public IFeedItem FeedItem
       {
           get { return feedItem; }
           set { feedItem = value; }
       }

       public string Title
       {
           get { return feedItem.Title; }
       }

       public string Description
       {
           get { return feedItem.Description; }
       }

       override public string ToString()
       {
           return Title;
       }
   }
}

Code for Form1.Designer.cs:

namespace RSSViewer
{
   partial class Form1
   {
       /// <summary>
       /// Required designer variable.
       /// </summary>
       private System.ComponentModel.IContainer components = null;

       /// <summary>
       /// Clean up any resources being used.
       /// </summary>
       /// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
       protected override void Dispose(bool disposing)
       {
           if (disposing && (components != null))
           {
               components.Dispose();
           }
           base.Dispose(disposing);
       }

       #region Windows Form Designer generated code

       /// <summary>
       /// Required method for Designer support - do not modify
       /// the contents of this method with the code editor.
       /// </summary>
       private void InitializeComponent()
       {
           this.components = new System.ComponentModel.Container();
           System.ComponentModel.ComponentResourceManager resources =
new System.ComponentModel.ComponentResourceManager(typeof(Form1));
           this.splitContainer1 = new
System.Windows.Forms.SplitContainer();
           this.tvFolders = new System.Windows.Forms.TreeView();
           this.imageList1 = new
System.Windows.Forms.ImageList(this.components);
           this.menuStrip1 = new System.Windows.Forms.MenuStrip();
           this.refreshToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
           this.splitContainer2 = new
System.Windows.Forms.SplitContainer();
           this.lbFeeds = new System.Windows.Forms.ListBox();
           this.webBrowserFeedOuput = new
System.Windows.Forms.WebBrowser();
           this.splitContainer1.Panel1.SuspendLayout();
           this.splitContainer1.Panel2.SuspendLayout();
           this.splitContainer1.SuspendLayout();
           this.menuStrip1.SuspendLayout();
           this.splitContainer2.Panel1.SuspendLayout();
           this.splitContainer2.Panel2.SuspendLayout();
           this.splitContainer2.SuspendLayout();
           this.SuspendLayout();
           //
           // splitContainer1
           //
           this.splitContainer1.Dock =
System.Windows.Forms.DockStyle.Fill;
           this.splitContainer1.Location = new System.Drawing.Point(0,
0);
           this.splitContainer1.Name = "splitContainer1";
           //
           // splitContainer1.Panel1
           //
           this.splitContainer1.Panel1.Controls.Add(this.tvFolders);
           this.splitContainer1.Panel1.Controls.Add(this.menuStrip1);
           //
           // splitContainer1.Panel2
           //
           
this.splitContainer1.Panel2.Controls.Add(this.splitContainer2);
           this.splitContainer1.Size = new System.Drawing.Size(939,
528);
           this.splitContainer1.SplitterDistance = 313;
           this.splitContainer1.TabIndex = 0;
           //
           // tvFolders
           //
           this.tvFolders.Dock = System.Windows.Forms.DockStyle.Fill;
           this.tvFolders.ImageIndex = 0;
           this.tvFolders.ImageList = this.imageList1;
           this.tvFolders.Location = new System.Drawing.Point(0, 24);
           this.tvFolders.Name = "tvFolders";
           this.tvFolders.SelectedImageIndex = 0;
           this.tvFolders.Size = new System.Drawing.Size(313, 504);
           this.tvFolders.TabIndex = 1;
           this.tvFolders.AfterSelect += new
System.Windows.Forms.TreeViewEventHandler(this.tvFolders_AfterSelect);
           //
           // imageList1
           //
           this.imageList1.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
           this.imageList1.TransparentColor =
System.Drawing.Color.Transparent;
           this.imageList1.Images.SetKeyName(0, "feed-icon-14x14.png");
           //
           // menuStrip1
           //
           this.menuStrip1.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
           this.refreshToolStripMenuItem});
           this.menuStrip1.Location = new System.Drawing.Point(0, 0);
           this.menuStrip1.Name = "menuStrip1";
           this.menuStrip1.Size = new System.Drawing.Size(313, 24);
           this.menuStrip1.TabIndex = 2;
           this.menuStrip1.Text = "menuStrip1";
           //
           // refreshToolStripMenuItem
           //
           this.refreshToolStripMenuItem.Name =
"refreshToolStripMenuItem";
           this.refreshToolStripMenuItem.Size = new
System.Drawing.Size(58, 20);
           this.refreshToolStripMenuItem.Text = "Refresh";
           this.refreshToolStripMenuItem.Click += new
System.EventHandler(this.refreshToolStripMenuItem_Click);
           //
           // splitContainer2
           //
           this.splitContainer2.Dock =
System.Windows.Forms.DockStyle.Fill;
           this.splitContainer2.Location = new System.Drawing.Point(0,
0);
           this.splitContainer2.Name = "splitContainer2";
           this.splitContainer2.Orientation =
System.Windows.Forms.Orientation.Horizontal;
           //
           // splitContainer2.Panel1
           //
           this.splitContainer2.Panel1.Controls.Add(this.lbFeeds);
           //
           // splitContainer2.Panel2
           //
           
this.splitContainer2.Panel2.Controls.Add(this.webBrowserFeedOuput);
           this.splitContainer2.Size = new System.Drawing.Size(622,
528);
           this.splitContainer2.SplitterDistance = 207;
           this.splitContainer2.TabIndex = 0;
           //
           // lbFeeds
           //
           this.lbFeeds.Dock = System.Windows.Forms.DockStyle.Fill;
           this.lbFeeds.FormattingEnabled = true;
           this.lbFeeds.Location = new System.Drawing.Point(0, 0);
           this.lbFeeds.Margin = new System.Windows.Forms.Padding(3, 6,
3, 6);
           this.lbFeeds.Name = "lbFeeds";
           this.lbFeeds.Size = new System.Drawing.Size(622, 199);
           this.lbFeeds.TabIndex = 1;
           this.lbFeeds.SelectedIndexChanged += new
System.EventHandler(this.lbFeeds_SelectedIndexChanged);
           //
           // webBrowserFeedOuput
           //
           this.webBrowserFeedOuput.Dock =
System.Windows.Forms.DockStyle.Fill;
           this.webBrowserFeedOuput.Location = new
System.Drawing.Point(0, 0);
           this.webBrowserFeedOuput.MinimumSize = new
System.Drawing.Size(20, 20);
           this.webBrowserFeedOuput.Name = "webBrowserFeedOuput";
           this.webBrowserFeedOuput.Size = new System.Drawing.Size(622,
317);
           this.webBrowserFeedOuput.TabIndex = 0;
           //
           // Form1
           //
           this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
           this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
           this.ClientSize = new System.Drawing.Size(939, 528);
           this.Controls.Add(this.splitContainer1);
           this.MainMenuStrip = this.menuStrip1;
           this.Name = "Form1";
           this.Text = "RSS Viewer";
           this.Load += new System.EventHandler(this.Form1_Load);
           this.splitContainer1.Panel1.ResumeLayout(false);
           this.splitContainer1.Panel1.PerformLayout();
           this.splitContainer1.Panel2.ResumeLayout(false);
           this.splitContainer1.ResumeLayout(false);
           this.menuStrip1.ResumeLayout(false);
           this.menuStrip1.PerformLayout();
           this.splitContainer2.Panel1.ResumeLayout(false);
           this.splitContainer2.Panel2.ResumeLayout(false);
           this.splitContainer2.ResumeLayout(false);
           this.ResumeLayout(false);

       }

       #endregion

       private System.Windows.Forms.SplitContainer splitContainer1;
       private System.Windows.Forms.SplitContainer splitContainer2;
       private System.Windows.Forms.TreeView tvFolders;
       private System.Windows.Forms.ListBox lbFeeds;
       private System.Windows.Forms.WebBrowser webBrowserFeedOuput;
       private System.Windows.Forms.ImageList imageList1;
       private System.Windows.Forms.MenuStrip menuStrip1;
       private System.Windows.Forms.ToolStripMenuItem
refreshToolStripMenuItem;
   }
}

--
Bryan Phillips
MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com

> > The RSS Feeds API is not actually a part of Outlook or IE, but you can
> > still access it via a type library.  Search MSDN for the "Feeds API".
[quoted text clipped - 5 lines]
>
> TIA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.