Working in Exchange 2000 with C#

  • Thread starter Thread starter ferg
  • Start date Start date
F

ferg

Hey folks,

I'm only beginning to understand the ins and outs of programming, let alone
C# and thing like ADO/CDO etc etc, but I'm on my way to trying to develop a
User Help Desk solution on Exchange 2000/2003 using C#.

I understand that E2K doesn't support ADO.Net (despite being a ".Net
Enterprise Server" or whatever), so would someone be able to point me in the
right direction for an easy way to work with Exchange messages, contacts and
folders which will minimise the work required in changing to Exch2003. One
person suggested WebDAV and XML but frankly I'm having a lot more difficulty
with that kind of stuff than I am with the old ADO!

Thanks in advance... oh, and if anyone can supply some code to extract a
list of messages from a folder that would be super (in the words of Big Gay
Al). :-)

Ferg.
 
Hi Freg,

Since you are familiar with ADO to exchange, you can still use them in C#
application through interop. For example, add CDO and ADO in COM
references, and with following code:

using System;

namespace Samples
{
class Class1
{
static void Main(string[] args)
{
try
{
ADODB.Connection oCn = new ADODB.Connection();
ADODB.Recordset oRs = new ADODB.Recordset();

ADODB.Fields oFields;
ADODB.Field oField;

// TODO: Replace with your folder URL
string sFdUrl = "http://ExchServer/exchange/UserAlias/Inbox";

oCn.Provider = "exoledb.datasource";
oCn.Open(sFdUrl, "", "", -1);


string strSql;
strSql = "";
strSql = "select ";
strSql = strSql + " \"urn:schemas:mailheader:content-class\"";
strSql = strSql + ", \"DAV:href\" ";
strSql = strSql + ", \"DAV:displayname\"";
strSql = strSql + " from scope ('shallow traversal of " + "\"";
strSql = strSql + sFdUrl + "\"') ";
strSql = strSql + " WHERE \"DAV:ishidden\" = false";
strSql = strSql + " AND \"DAV:isfolder\" = false";
strSql = strSql + " AND \"DAV:displayname\" = 'Test.eml'"; // TODO:


oRs.Open(strSql, oCn,
ADODB.CursorTypeEnum.adOpenUnspecified,
ADODB.LockTypeEnum.adLockOptimistic,
1);

Console.WriteLine(oRs.RecordCount);

oRs.MoveFirst();
while(!oRs.EOF)
{

oFields = oRs.Fields;

oField = oFields["DAV:href"];
Console.WriteLine(oField.Value);

oField = oFields["DAV:displayname"];
Console.WriteLine(oField.Value);

oRs.Delete(ADODB.AffectEnum.adAffectCurrent);

oRs.MoveNext();
Console.WriteLine("Item Deleted");
Console.WriteLine("--------------------------");

}

oCn.Close();

oCn = null;
oField = null;
oFields = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}
}


Some KB article on this issue will be released soon, on how to access
exchange server with C#.


Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."
 
Back
Top