My exchange services works. I can see all rooms by Outlook and Can see all rooms through Powershell.
But with this snippet I cannot retrieve any room
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.UseDefaultCredentials = true;
service.Url = new Uri("https://my server/ews/exchange.asmx");
service.AutodiscoverUrl("username#myserver.com", RedirectionCallback);
EmailAddressCollection myRoomLists = service.GetRoomLists();
// Display the room lists.
foreach (EmailAddress address in myRoomLists)
{
Console.WriteLine("Email Address: {0} Mailbox Type: {1}", address.Address, address.MailboxType);
}
The list is empty!
It sounds like your Exchange administrator has not configured any room lists. EWS depends on the presence of room lists in the GAL to work. See https://technet.microsoft.com/en-us/library/jj215781(v=exchg.150).aspx for details.
See here for more info. You need to iterate through the room lists within the collection you got from GetRoomLists(), and then iterate through the conference rooms in each room list using service.GetRooms(myRoomList).
Related
I am trying to programmatically add a member (name and email address) to an existing Outlook Distribution List, but I can figure out how to grab it. I have found many postings describing how to create a new Outlook Distribution List, but none on how to add a member to an existing one. I have been able to retrieve the items collection of the Contacts folder, but I cannot access the Outlook Distribution List I want. Keep in mind that the Contacts folder contains at least two different object types, Contact Items and Distribution List items. Is there a way to just retrieve the Distribution List items from the Contacts folder? Any help would be greatly appreciated. I have no code worth posting.
I have made some progress. I now have the below code:
Outlook.MAPIFolder outlookContactsFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); // Get Contacts folder.
Outlook.Items outlookContactsItems = outlookContactsFolder.Items; // Get the Items collection.
for (int i = 1; i <= outlookContactsItems.Count; i++)
{
if (i == 62)
{
Outlook.DistListItem outlookDistListItem = outlookContactsItems.GetNext();
Outlook.Recipient outlookRecipient = **(Need help creating a Recipient object with a name and email address)**
outlookDistListItem.AddMember(outlookRecipient);
outlookDistListItem.Save();
break;
}
else
{
Outlook.ContactItem outlookContactsItem = outlookContactsItems.GetNext();
}
}
I know this is not the best way, but it works. I can now access the Distribution List without the code blowing up. Now I need to add a new member to it. I know I can do that with the AddMember method, but it takes an Outlook.Recipient object. I can't find anywhere how to create it with a name and email address.
We're on exchange 2007 and I'm using php-ews and I want to get a list of all the bookings for a room resource. By room resource, I mean the rooms button in outlook when creating a meeting invite.
The code I have so far returns items from my calendar but I need calendar from 'Conference room A'. Anyone have done this?
$host = 'mailhost';
$username = 'xxxx';
$password = 'xxxx';
$mail = 'xxxx';
$startDateEvent = "2013-01-14T09:00:00";
$endDateEvent = "2013-09-20T17:00:00";
$ews = new ExchangeWebServices($host, $username, $password);
$request = new EWSType_FindItemType();
$request->Traversal = EWSType_FolderQueryTraversalType::SHALLOW;
$request->CalendarView->StartDate = $startDateEvent;
$request->CalendarView->EndDate = $endDateEvent;
$request->CalendarView->MaxEntriesReturned = 100;
$request->CalendarView->MaxEntriesReturnedSpecified = true;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = $mail;
$response = $ews->FindItem($request);
echo '<pre>'.print_r($response, true).'</pre>';
I'm even later to the game. But The way I solved this was to create an exchange account after the name of the room, for instance boardroom#.
Then I got people to copy in boardroom# whenever they sent out a meeting request. My scripts simply interrogate boardroom#'s calendar. Everyone at the organisation has a copy of boardroom's calendar in read-only mode that they can look at to see all the meetings that week.
My software was for a display sign outside the room that showed whether the room was in use or not based upon this calendar.
Late to the game but maybe this will help someone....
Basically, php-ews never added the GetRooms operation. You could modify your app to perform the room lookup via ldap (assuming your rooms exist in AD) and then use the email address of each room and query it's calendar using impersonation.
See my answer here...
https://stackoverflow.com/a/23815914/2979715
I have a bunch of custom entity records in a List (which comes from a csv file).
What is the best way to check which records are new and create those that are?
The equality check is based on a single text field in this case, but I need to do the same thing elsewhere where the equality check is based on a lookup and 2 text fields.
For arguments sake lets say I was inserting Account records, this is what I currently have:
private void CreateAccounts()
{
var list = this.GetAccounts(); // get the list of Accounts, some may be new
IEnumerable<string> existingAccounts = linq.AccountSet.Select(account => account.AccountNumber); // get all Account numbers in CRM, linq is a serviceContextName variable
var newAccounts = list.Where(account => !existingAccounts.Contains(account.AccountNumber)); // Account numbers not in CRM
foreach (var accountNumber in newAccounts) // go through the new list again and get all the Account info
{
var account = newAccounts.Where(newAccount => newAccount.AccountNumber.Equals(accountNumber)).FirstOrDefault();
service.Create(account);
}
}
Is there a better way to do this?
I seem to be iterating through lists too many times, but it must be better than querying CRM multiple times:
foreach (var account in list)
{
// is this Account already in CRM
// if not create the Account
}
Your current method seems a bit backwards (get everything out of CRM, then compare it to what you have locally), but it may not be too bad depending on how many accounts you have ie < 5000.
For your simple example, you should be able to apply a where in statement.
Joining on multiple fields is a little more tricky. If you are running CRM > R12, you should be able to use the ExecuteMultipleRequests, creating a seperate request for each item in your list, and then batching them all up, so there is one big request "over the wire" to CRM.
As far as I am now, I know how to fetch appointments from exchange server, BUT as soon as I want to see the required and optional attendees, these fields are empty ... I checked the appointment trice and there is an attendee, except me. Do I have to config Outlook differently or do I miss something?
List<Appointment> listOfAppointments = new List<Appointment>();
CalendarFolder cfolder = CalendarFolder.Bind(MyService, WellKnownFolderName.Calendar);
CalendarView cview = new CalendarView(from.ToUniversalTime(), to.ToUniversalTime());
cview.PropertySet = new PropertySet(ItemSchema.Subject);
cview.PropertySet.Add(AppointmentSchema.Start);
cview.PropertySet.Add(AppointmentSchema.End);
cview.PropertySet.Add(AppointmentSchema.Location);
cview.PropertySet.Add(AppointmentSchema.ICalUid);
cview.PropertySet.Add(AppointmentSchema.Organizer);
cview.PropertySet.Add(AppointmentSchema.IsAllDayEvent);
cview.PropertySet.Add(AppointmentSchema.DateTimeCreated);
FindItemsResults<Appointment> result = cfolder.FindAppointments(cview);
thats how I fetch the appointments, as I figured from exceptions and trail and error, I don't need to ask exchange for attendees... but maybe I am missing something.
The FindAppointments operation do not return the attendees of meetings. Instead, specify a propertyset of PropertySet.IdOnly to get only the ids of the items. Then, use the ExchangeService.LoadPropertiesForItems to perform a batch load of the properties you need.
I'm using a CalendarItemType view to retrieve calendar items. The only items I care about are those that I've created and I know that they are all weekly recurring items. I'm able to get each individual occurrence and, from any one of them the recurring master item, but I'd like to narrow the scope of my search to just those items that would match my pattern.
I've trying using the Restriction property on the FindItemType to specify a NotEqualTo restriction with a null constant for calenderRecurrenceId. This caused my request to time out. So far I've been unable to load the recurrences with the FindItemType at all and need to use a subsequent GetItemType call when I find an event that is an occurence in a recurring series.
Here's the code that I'm starting with. The code needs to work with both Exchange 2007 and Exchange 2010.
var findItemRequest = new FindItemType();
findItemRequest.ParentFolderIds = new DistinguishedFolderIdType[]
{
new DistinguishedFolderIdType()
};
((DistinguishedFolderIdType)findItemequest.ParentFolderIds[0]).Id = DistinguishedFolderIdNameType.calendar;
findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
var itemShapeDefinition = new ItemResponseShapeType(
{
BaseShape = DefaultShapeNamesType.AllProperties;
}
findItemRequest.Item = calenderView;
findItemRequest.ItemShape = itemShapeDefinition;
var findItemResponse = this.esb.FindItem( findItemRequest );
Also, if you know of any good source of examples (beyond the ones in MSDN), I'd welcome them. I'm picking up someone else's code in an emergency and trying to learn Exchange Web Services on the fly.
Maybe I'm misunderstanding you, in which case I apologize.
You do NOT use the CalendarView - you use the normal IndexedPageItemView if all you want is Master Recurring Calendar items.
You use the CalendarView to expand the recurrences to individual items. However the compromise with CalendarView is NO restrictions are permitted besides Start and End Date. None.
You can search for a RecurrenceMaster by using the recurrence PidLid with an ExtendedPropertyDefinition. This works because, according to their documentation, "this property must not exist on single instance calendar items."
https://msdn.microsoft.com/en-us/library/cc842017.aspx
// https://msdn.microsoft.com/en-us/library/cc842017.aspx
ExtendedPropertyDefinition apptType = new ExtendedPropertyDefinition(
DefaultExtendedPropertySet.Appointment,
0x00008216, //PidLidAppointmentRecur
MapiPropertyType.Binary);
var restriction = new SearchFilter.Exists(apptType);
var iView = new ItemView(10);
var found = folder.FindItems(restriction, iView);
I just confirmed this works, today, when revisiting some old code that works with Office365 EWS in the cloud.
Found only property you need is RecurrenceStart property. Because EWS has limitations it is not possible to use all properties in restriction. This one working as expected.
Reference: Find master recurring appointments
You can create custom searchfilters. If you search from specific startdate OR isRecurring property you have most easy way...(SearchItems returns recurring masters)
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
SearchFilter.IsGreaterThanOrEqualTo startDatumFilter = new SearchFilter.IsGreaterThanOrEqualTo(AppointmentSchema.Start, new DateTime(2012, 9, 16));
SearchFilter.IsEqualTo masterRecurringFilter = new SearchFilter.IsEqualTo(AppointmentSchema.IsRecurring, true);
searchFilterCollection.Add(startDatumFilter);
searchFilterCollection.Add(masterRecurringFilter);
SearchFilter finalFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection);
ItemView itemView = new ItemView(100000);
itemView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointmentSchema.AppointmentType);
FindItemsResults<Item> items = _service.FindItems(WellKnownFolderName.Calendar, finalFilter, itemView);