Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 9th, 2003, 02:53 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default c#, ADSI, DirectoryService and Exchange 5.5

I wonder if I can use c# and DirectoryService to manipulate an Exchange 5.5 mailbox account..

I did some test, and I can read the mailbox information (from exchange 55). But I cannot create an new mailbox and I cannot search it..

here are my code,, can anyone help? thanks..
================================================== ====

// here: the Ldappath, I put in is "LDAP://exchangeservername"
// mailboxdirname is a mailbox directory name

// I cannot find anything, even I put into a existing mailbox
// directory name,, don't know what's going on.

public int SearchExchange(string LDAPPath, string mailboxDirectoryName)
        {
            DirectoryEntry searchroot = new DirectoryEntry(LDAPPath);
            DirectorySearcher ds = new DirectorySearcher(searchroot);
            ds.SearchScope = SearchScope.Subtree;
            ds.Filter = "(&(objectClass=person)(cn=" + mailboxDirectoryName + "))";
            SearchResultCollection results = ds.FindAll();
            return results.Count;
// switch (results.Count)
// {
// case 0: //cannot find any account
// return null;
// case 1: //find exactly the entry
// return results[0].GetDirectoryEntry();
// default: // error occured
// throw(new ApplicationException("An error occurred in Exchange. Duplicate accounts found."));
// }
        }


// for saving, I always get either "conflict violation"
// or "properties not found.. wired..
public void Save()
        {
            try
            {
                DirectoryEntry mailboxContainer = new DirectoryEntry("LDAP://exchangeservername/o=exchangeOrg/ou=exchangesite/cn=Recipients","administrator","password");
                DirectoryEntry mailbox = mailboxContainer.Children.Add("cn=george 1234","organizationalPerson");
                mailbox.Properties["mailPreferenceOption"].Value = "0";
                mailbox.Properties["rdn"].Value = "huang123rdn";
                //mailbox.Properties["givenName"].Value = "george";
                mailbox.Properties["sn"].Value = "huang";
                mailbox.Properties["uid"].Value = "huang1234";
                //mailbox.Properties["mail"].Value = "[email protected]";
                //mailbox.Properties["MAPI-Recipient"].Value = (bool)true;
                mailbox.Properties["rfc822Mailbox"].Value = "[email protected]";


                // ' Commit the property cache to the directory service
                mailbox.CommitChanges();
            }
            catch(Exception ex)
            {
                throw ex;
            }

 
Old October 9th, 2003, 04:12 PM
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am able to search the Exchange 55 using c# now...

for my previous mail,, if I thought cn is the directory name, but actually cn in exchange is "display name" and rdn is directory name.

so just change the filter, and it works:

ds.Filter = "(&(objectClass=organizationalPerson)(uid=" + mailboxAliasName + "))";

Still trying to figure out how to create a new mailbox.

George






Similar Threads
Thread Thread Starter Forum Replies Last Post
ADSI mikedeepak Classic ASP Professional 1 August 13th, 2004 06:33 PM
Create ADSI User and Exchange Mailbox vbsdp Pro VB 6 2 May 26th, 2004 04:40 PM
ADSI problem yeewaitu Classic ASP Professional 5 February 24th, 2004 03:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.