CDOEXM & C#.Net : How to mail-disable public folders in Exchange Server 2003 SP2 – Native Mode?

I created this code snippet, which helps us to mail-disable in the Exchange Server 2003 SP2 (Native mode) – public folders. For this i tried this, i used C#.Net & CDOEXM. In this below code, i try to mail-disable the public folder named “publicfolder1”. I used Visual Studio.Net 2008, C#.Net and CDOEXM – Collaboration Data Objects for Exchange Management – 2003 to do this:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using CDO;
 using CDOEXM;
 using System.Collections; 
 namespace MailDisableCSharp
 {
     class Program
     {
         static void Main(string[] args)
         { 
  
             try
             {
                 CDO.Folder objFolder = new CDO.Folder();
                 CDOEXM.IMailRecipient objRecip;
                 string fullurl;
                 fullurl = "https://domain/public/publicfolder1";
  
                 objFolder.DataSource.Open(
                                 fullurl,
                                 null,
                                 ADODB.ConnectModeEnum.adModeReadWrite,
                                 ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
                                 ADODB.RecordOpenOptionsEnum.adOpenExecuteCommand,
                                 "Administrator",
                                 "Password"); 
  
                 objRecip = (CDOEXM.IMailRecipient)objFolder;
                 objRecip.MailDisable();
                 objFolder.DataSource.Save();
                 Console.Write("Success");
              }
             catch (Exception e1)
             {
                 Console.WriteLine(e1.Message);
            } 
  
         }
     }
 }

Note:

+ To execute this code, you may try with VS.Net 2005 or VS.Net 2008, C#.Net.

+ Make sure you need to use the following references: CDOEXM – Microsoft CDO for Exchange Management 2000 & CDOEX - Microsoft CDO for Exchange 2000.

+ This code helps us to mail-disable the public folder “public folder1”.

+ Also we need to make sure to pass valid credentials username(Administrator) & password(Password) to execute this, along with valid fullURL – the public folder needs to be mail-disabled & domain – exchange domain.

Hope this helps. Happy programming!!