17 February 2009

Delete all Outlook RSS Feeds

My Outlook RSS Feeds were in a really funky state this morning.  I had to create a new profile and I had RSS Sync enabled.  When that is the case Outlook re-adds all Feeds that you have ever added to the machine back into your profile even if you previously deleted them using the Outlook UI.

After many failed attempts to fix this with the help of a few folks internally I decided to write a quick script to delete all RSS feeds in Outlook.

I first try to delete and if that fails I move the folder to the Deleted Items folder.  (The delete was failing for me for some unobvious permission issue).

 

This was the exception:

Cannot delete this folder. Right-click the folder, and then click Properties to check your permissions for the folder.  See the folder owner or your administrator to change your permissions.  You don’t have appropriate permission to perform this operation.

Technorati Tags: ,,,,,,,,,,,,

 

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using Microsoft.Office.Interop.Outlook;
   6:   
   7:  namespace OutlookRssDelete
   8:  {
   9:      class Program
  10:      {
  11:          static void Main(string[] args)
  12:          {
  13:              Application app = new Application();
  14:              NameSpace ns = app.GetNamespace("MAPI");
  15:   
  16:              MAPIFolder feeds = ns.GetDefaultFolder(OlDefaultFolders.olFolderRssFeeds);
  17:              MAPIFolder delitems = ns.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems);
  18:   
  19:              // Put in temp because we need to delete from the same list
  20:              List<MAPIFolder> feedFolders = new List<MAPIFolder>();
  21:              foreach (MAPIFolder f in feeds.Folders)
  22:              {
  23:                  feedFolders.Add(f);
  24:              }
  25:   
  26:              foreach (MAPIFolder f in feedFolders)
  27:              {
  28:                  Console.WriteLine(f.Name);
  29:                  try
  30:                  {
  31:                      
  32:                      f.Delete();
  33:                  }
  34:                  catch
  35:                  {
  36:                      try
  37:                      {
  38:                          Console.WriteLine("Delete failed.  Try Moving to Deleted Items");
  39:                          f.MoveTo(delitems);
  40:                      }
  41:                      catch (System.Exception ex1)
  42:                      {
  43:                          Console.WriteLine("Move to Deleted Items Failed. Call Helpdesk :) " + ex1.ToString());
  44:                      }
  45:                      
  46:                  }
  47:              }
  48:          }
  49:      }
  50:  }
Filed under: , , , ,
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Page view tracker