Accessing a Resource Calendar with no mailbox via EWS and C# - c#

Our Exchange Admins (Exchange 2010 SP1) have setup a shared resource calendar. There is no mailbox assigned to this resource calendar. I want to be able to read the meetings using EWS and C#.
Snippet:
ExchangeService esvc = new ExchangeService(ExchangeVersion.Exchange2010);
esvc.Credentials = new WebCredentials(username, password, "ourplace.org");
esvc.Url = new Uri("https://OWA.OURPLACE.ORG/EWS/Exchange.asmx");
FolderId shareFolderId = new FolderId(WellKnownFolderName.Calendar, "Shared Calendar Name");
CalendarFolder.Bind(esvc, shareFolderId);
the bind statement throws the error: "The SMTP address has no mailbox associated with it."
How can I read the items on a Share Resource Calendar that has no associated mailbox... or is it even possible?
Thanks !!

Bind to that Calendar with a mail-Adress
Create first of all a FolderId:
FolderId parkplatzCalendarId = new FolderId(WellKnownFolderName.Calendar,"de.calendar.name#company.com");
Then bind to this one:
CalendarFolder calendar = CalendarFolder.Bind(_service, parkplatzCalendarId);
Now you can use this calendar!
CalendarView cView = new CalendarView(start, end, int.MaxValue);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Duration, AppointmentSchema.LastModifiedName, AppointmentSchema.Organizer, AppointmentSchema.Categories);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
With something like that ;D

If the calendar is actually not in any particular mailbox, then it should be in a public folder, and you should look in a subfolder WellKnownFolderName.PublicFoldersRoot.
Otherwise, please tell where exactly does it appear in Outlook folders hierarchy.

Related

Outlook 2016 showing appointment Icon even for meetings created with EWS API

I'm creating appointments and meeting with EWS managed API but however, I found the Icon's appearing wrongly in Outlook 2016.
Creating meetings with msdn example ` ExchangeService service = GetExchangeService();
Appointment meeting = new Appointment(service);
// Set the properties on the meeting object to create the meeting.
meeting.Subject = "EWS : Meeting";
meeting.Body = "Let's learn to really work as a team and then have lunch!";
meeting.Start = DateTime.Now.AddDays(2);
meeting.End = meeting.Start.AddHours(4);
meeting.Location = "Conference Room 12";
meeting.RequiredAttendees.Add("attendee1");
meeting.RequiredAttendees.Add("attendee2");
meeting.ReminderMinutesBeforeStart = 60;
//// Save the meeting to the Calendar folder and send the meeting request.
meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
// Verify that the meeting was created.
Item item = Item.Bind(service, meeting.Id, new PropertySet(BasePropertySet.FirstClassProperties));
Console.WriteLine("\nMeeting created: " + item.Subject + "\n");`
But the Icons are like this .
Here , Subject starting with "EWS" created using API and subject with "Outlook" are manually created in outlook. Outlook meeting has different Icon.
Any workaround for this problem?
You could try setting the PR_Icon_Index property https://msdn.microsoft.com/en-us/library/office/cc815472.aspx which you should be able to set using a Extended property to 0x00000402 for a single instance meeting.

Creating appointments on other calendars, shared with me, using EWS API

I hope this is the right forum to ask this question.
My requirement is as mentioned below:
-> I need to create an appointment on my Default calendar and the same on other calendars that are shared with me (or created by me and shared with others) by using Exchange Services (EWS).
-> By shared, i mean all those calendars that I can see under my 'Other Calendars' group in Office 365.
-> Now, I have reffered many links which help to create appointments on my mailbox, default Calendar. This part works fine(Link : (http://technico.qnownow.com/how-to-create-appointment-using-ews-exchange-web-services/)
-> Then I moved on to access shared calendars so that I can create the same appointment on them.
Used this : EWS - Access All Shared Calendars
-> However I do not get the PidTagWlinkAddressBookEID property in any of the items fetched.
The code works fine till I get the fiResults collection.
I get names of all the calendars under Other Calendars section in this collection.
The problem is when I iterate over this collection (as you can see in the code) , i am trying to get the PidTagWlinkAddressBookEID property value in each item and its not present in the item.
And this is the reason I am not able to retrieve the FolderID at the end.
But i tried number of ways to do it since i get the collection of items and I can see my shared calendars' names in those items.
Since i created the shared calendars, I tried to use my mailbox address at the end in this part of the code :
FolderId SharedCalendarId = new FolderId(WellKnownFolderName.Calendar, ncCol[0].Mailbox.Address);
However the calendar retrieved in this case is the default calendar with displayName as Calendar.
Since each item in the itemcollection ( fiResults collection) represents the corresponding shared calendar
Please let me know if we can use any property in the Item class to create an appointment.
I tried one more approach to create appointments on shared calendars:
First i tried to access all the calendar folders by using:
private void ViewCalendarFolders(string mailBox)
{
ExtendedPropertyDefinition PR_Folder_Path = new ExtendedPropertyDefinition(26293, MapiPropertyType.String);
PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
psPropSet.Add(PR_Folder_Path);
FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root, mailBox);
FolderView fvFolderView = new FolderView(1000);
fvFolderView.Traversal = FolderTraversal.Deep;
fvFolderView.PropertySet = psPropSet;
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.FolderClass, "IPF.Appointment");
FindFoldersResults ffoldres = exchangeService.FindFolders(rfRootFolderid, sfSearchFilter, fvFolderView);
var res = ffoldres.Where(f => f is CalendarFolder).ToList();
if (res.Any())
{
foreach (Folder fld in res)
{
Console.WriteLine(fld.DisplayName);
}
}
}
Then I tried to create appointments on the CalendarFolders fetched.
I succeeded in creating appointments on two calendars:
1) My default calendar
2) The calendar which I have created and shared with others.
the piece of code shown above fetches all the calendar folders except those which are created by other users and shared with me. (Even though I can see them under the Other Calendars section in office 365 and can even create appointments on them through UI i.e. manually)
Kindly let me know how to create appointments on such calendars which are shared by others with me.
Note: I have Editor rights on these type of calendars
Thanks

MS Exchange server cloud, getting all items in a different

I am trying to figure out how to access all items from a 'room' account.
Is it possible to somehow access the data from the room when that user isn't a real user?
I can get all rooms but the question is how to query the finditems using the room account.
You will need to authenticate as some user with a Mailbox and then grant that user access to the Room's Calendar (or the whole mailbox using Add-MailboxPermissions) or make it a delegate. Then you can just use the FolderId overload to specify you want to query that Room's Calendar folder eg
FolderId RoomMailboxCalendarFolderId = new FolderId(WellKnownFolderName.Calendar, "room#domain.com");
CalendarView cvCalView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(31));
FindItemsResults<Appointment> appointments = service.FindAppointments(RoomMailboxCalendarFolderId, cvCalView);
Cheers
Glen

How to use Microsoft Exchange Web Services to retrieve meeting form other contacts in the same domain?

I would like to retrieve calender items from Outlook 2010. Currently I could only retrieve items from my own calender by following this tutorial. But I want to get meeting from my colleagues calender. I have tried many option so far but nothing is working. Could you please show me how to use these api to get all calender meeting from the same exchange server? Thanks in advance!
Well, there is no answer within 2 days. Meanwhile I found a way to access others calender. I want to share my solution so that other can get a helsp:-
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials();
Mailbox principle = new Mailbox("usedr#domain.com");
CalendarFolder calendar2 = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, principle), new PropertySet());
// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> appointments2 = calendar2.FindAppointments(cView2);
appointments2 should have all the calender meeting.

ServiceResponseException: The specified object was not found in the store

I am trying to upgrade an application that uses WebDAV against Exchange 2003 to return a responseXML, then it creates cases on SalesForce CRM (using web service wsdl) and puts the attachments from the emails on the cases.
We are moving to Exchange 2010 SP2 so I need to access the inbox using EWS.
I am getting a ServiceResponseException error "The specified object was not found in the store."
Here is my code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);// .Exchange2007_SP1);
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)));
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments,true)));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(#"bbtest#domain");
ItemView view = new ItemView(1);
//creates a folder object that will point to inbox folder
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
service.Url = new Uri("https://domain/EWS/Exchange.asmx");
//this will bind the mailbox you're looking for using your service instance
Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, fid);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
foreach (EmailMessage email in results)
{
Debug.Print(email.From.ToString());
Debug.Print(email.DisplayTo);
Debug.Print(email.Subject);
}
it throws the error on this line:
Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, fid);
what am I doing wrong and how can I fix this please?
Also, is there no way to get EWS to return similar XML responseStream as webDAV?
In my experience, NotFound can be returned when you do not have permission to access the object in the Exchange store. Make sure that whatever credentials you use had full mailbox access rights to the target MB. (I suppose if all you want to do is read items, you might need fewer permissions, but you can trim later on if needed.) I don't see you setting any credentials in the above, so presumably you are accessing EWS with your default creds, i.e. what you're logged in as when running this.
And no, you cannot get a WebDAV response stream from EWS: they are totally different services, and as I'm sure you're aware, WebDAV does not exist after E2007.

Categories