Link to home
Start Free TrialLog in
Avatar of ClaudeWalker
ClaudeWalker

asked on

EWS Autodiscover not working, cycle through calendar items

I'm trying to create a program that cycles through all user calendars and records their calendar items.  However, I can't seem to do anything other than access my calendar.  I'm the Systems Administrator and have access to all admin accounts and admin network credentials.

How can I get a user's (other than mine) calendar items?  I get autodiscover errors so I am putting in the service URL directly.

Thanks,
JOe K.


//THIS WORKS

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

service.UseDefaultCredentials = true;
service.Url = new Uri ("https://mydomain/EWS/Exchange.asmx");
                
                Appointment appointment = new Appointment(service);
                appointment.Subject = "Dentist Appointment";
                appointment.Body = "The appointment is with Dr. Smith.";
                appointment.Start = new DateTime(2012, 1, 3, 9, 0, 0);
                appointment.End = appointment.Start.AddHours(2);
                appointment.Save(SendInvitationsMode.SendToNone);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ClaudeWalker
ClaudeWalker

ASKER

That definitely helps.  Now I need to Enable Impersonation on the account:

Per the documentation to enable it for all users:

New-ManagementRoleAssignment –Name:impersonationAssignmentName –Role:ApplicationImpersonation –User:serviceAccount

However, I don't know what the parameters are supposed to me :

impersonationAssignmentName (is this just an arbitrary named thing, could I keep it the same
ApplicationImpersonation (Is this meant to be as is)
serviceAccount (is this an email account, sharedTest@mydomain.com)

I'm close...

Thanks,
JOe K.
You must left all the data as the way you wrote it except for "serviceAccount" that must be your account (your user name into the domain, the one which you log in with).

Hope that helps.
I'm still getting the same error even after adding that to EMS.

Here is my code:

Here is what I used to enable impersonation:  New-ManagementRoleAssignment –Name:impersonationAssignmentName –Role:ApplicationImpersonation –User:userLogin

 
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                    service.Url = new Uri("https://myDomain.com/EWS/Exchange.asmx");
           
                    service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "userLogin@myDomain.com");
                    
                    Folder folder = Folder.Bind(service, WellKnownFolderName.Calendar);
                               
                    Console.WriteLine(folder.DisplayName);

Open in new window

Sorry about the tabbing in the embedded code.
Nevermind, this was the issue:  Console.WriteLine(folder.DisplayName);

I can get Console.WriteLine(folder.Id); to work instead meaning its connecting.
Now I have access to the calendar folder for all users

how can I grab the calendar items using folder.???
Does Console.WriteLine(folder.Id) works?
Yes.  I got it!

foreach (Item item in calendar.FindItems(new ItemView(100)))
{
     Console.WriteLine(item.Subject);
}


I was able to cycle through all of the items in a calendar.  Now I can put some date conditions in and loop through a number of email addresses.

Perfect!

Thank you soooo much!

JOe K.
Glad to help you!!

Greetings and happy new year!