How to remove a outlook rule?

Jul 7, 2011 at 5:28 AM

Hello,

        I  want to delete a outlook rule with Outlook._Rules.Remove(),but it doesn't seem to work.

        VS2010 doesn't show any problem but the rule which name is "AAA" still existes in my Outlook.

// pls read following program         

   LateBindingApi.Core.Factory.Initialize();

 Outlook.Application outlookApp = new Outlook.Application();

Outlook._NameSpace outlookNS = outlookApp.GetNamespace("MAPI");

Outlook.Rules rules = outlookNS.DefaultStore.GetRules();
MessageBox.Show("Rules count is:"+rules.Count);

 for(int k=1;k<=rules.Count;k++)
            {
                Outlook._Rule rule = rules[k];

              
                if(rule.Name.Equals("AAA"))
                {
                    Object ccc=(Object)rule.Name;
                    rules.Remove(ccc);
                    MessageBox.Show("Remove it");
                }