none
Outlook.AppointmentItem and UID RRS feed

  • Question

  • Hi,

    I create solution to my SharePoint calendar, and I connected my Outlook calendar to sharepoint with incoming e-mail enabled.

    How can I find event with UID?

    I use Outlook.AppointmentItem in C sharp

    string appSubject = properties.ListItem["Cím"].ToString();
    Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem)oItems.Find(String.Format("[Subject]='{0}'", appSubject ));
    oAppt.Start = Convert.ToDateTime(properties.ListItem["Kezdő időpont"]);
    oAppt.End = Convert.ToDateTime(properties.ListItem["Záró időpont"]);
    oAppt.Save();

    This work good, If I use subject, but I want to use ID

    string appointmentID = properties.ListItem["E-mail – naptár UID azonosítója"].ToString();

    Please help!

    Thanks,

    Niki

    Monday, March 12, 2012 3:02 PM

Answers

  • Ok, so disregarding that you automate outlook in IIS, here is one of possible solutions to this problem:

    - since this is not a connected sharepoint list, STS* properties will not be present. You have to maintain your own bookkeeping which apointment related to which listitem in sharepoint. Add UserProperty like ListItemId (remember to pass true to add it also to folder level) and in event reciever read Item["ID"] and use DASL to find your corresponding appointmentItem in outlook, like: Items.Find("@SQL=http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/ListItemId = 123") to find item with id 123.

    There are some things that you have to remember - in series you will have MasterSeriesItemId that points to master list item - depending on EventType you will have to remember to either find series appointmentitem or single occurance (existing or create one if needed).

    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:21 AM
    Tuesday, March 13, 2012 11:19 AM
  • Looking at the ID data, it does look like a regular Outlook appointment id (starts with 04).

    Do you see it in Outlook if you select the appointment and then use OutlookSpy (click Item and IMessage buttons)? 


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:21 AM
    Tuesday, March 13, 2012 5:31 PM

All replies

  • I don't quite understand what you are trying to do.  Are you referring to the AppointmentItem.EntryID property?  Do you want to use that value to get a specific appointment?  If so, use the NameSpace.GetItemFromID method.

    Eric Legault
    MVP (Outlook)
    About me...

    Monday, March 12, 2012 3:26 PM
    Moderator
  • i think it should be in ows_UID - properties.ListItem["ows_UID"]

    Please remember that UID will only be available in appointments with series - for single occurence ones it will not be present.

    Monday, March 12, 2012 3:54 PM
  • Use AppointmentItem.GlobalAppointmentID property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    Monday, March 12, 2012 4:44 PM
  • Sorry, I try to compose understandably.

    I have sharepoint calendar, who I set incoming e-mail enabled, and I send event to my sharepoint calendar from my outlook calendar.

    I want to create Event Receiver, who I update the appointment in sharepoint and I want to search this appointment in outlook and refresh it.

    Tuesday, March 13, 2012 7:25 AM
  • If I send event to my SharePoint calendar, than automatically configure the UID field in SharePoint, even if it does not appointments with series.

    Tuesday, March 13, 2012 7:35 AM
  • on my system when i connect sharepoint calendar to outlook, UID is only assigned to appointments that are recurring (ows_Recurrence =1). And GlobalAppointmentID on those items/calendar will be empty. If you want to identify that items in outlook, look for property STS_Id (access it using PropertyAccessor with http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/STS_Id) - it will be an Id of item in sharepoint list. Unless i somehow misunderstood your problem - in such case explain again and show some screenshots.

    Tuesday, March 13, 2012 8:28 AM
  • My sreenshot: http://kepfeltoltes.hu/view/120313/calendar_www.kepfeltoltes.hu_.png

    I thought the search by UID, because If I search by subject, then i'm not sure, that finds one.

    My goalisto findthe modifiedevent.

    Tuesday, March 13, 2012 8:42 AM
  • subject can be the same on mutiple different appointments so this is a road to nowhere.

    What do you mean that your goal is to find the modified event? mofidied event where?

    Tuesday, March 13, 2012 9:13 AM
  • I modified the event in sharepoint - I change the Start Date, than come the event receiver and find this event in Outlook and update.
    Tuesday, March 13, 2012 9:19 AM
  • outlook by itself will grab this new appointment properties after some time (or you can force it with send/recieve button). But if you want to make this manually you have to look for appointment item with STS_Id property matching that of changed item. But there are few problems with that approach:

    1. How do you want to modify something in outlook from inside event reciever in sharepoint?

    2. More importnant problem - what if your change created exception that does not exist yet in outlook?

    Tuesday, March 13, 2012 9:59 AM
  • public override void ItemUpdated(SPItemEventProperties properties)
           {
               base.ItemUpdated(properties);
               base.EventFiringEnabled = false;
               SPWeb web = properties.OpenWeb();
               SPUser user = web.CurrentUser;
               
               string login = user.LoginName.ToString();
    
               Outlook.Application oApp = new Outlook.Application();
               Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
               oNS.Logon(Missing.Value, Missing.Value, true, true);
    
               Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
               Outlook.Items oItems = oCalendar.Items;
    
               SPListItem item = properties.ListItem;
               string appointmentID = item["E-mail – naptár UID azonosítója"].ToString();
               string appSubject = item["Cím"].ToString();
               Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem)oItems.Find(String.Format("[Subject]='{0}'", appSubject ));
               oAppt.Start = Convert.ToDateTime(item["Kezdő időpont"]);
               oAppt.End = Convert.ToDateTime(item["Záró időpont"]);
               
               oAppt.Save();
               oNS.Logoff();
               oApp = null;
               oNS = null;
               oAppt = null;
               base.EventFiringEnabled = true;
    
               
           }
    This is my working code If I search item by Subject.
    Tuesday, March 13, 2012 10:07 AM
  • Where is this event reciever running? on server in IIS?

    I would strongly recommend using EWS to do this manipulation of appointments in someone's calendar.

    Tuesday, March 13, 2012 10:12 AM
  • Yes, on server.

    In my other solution I use EWS, but in this solution I don't want to use, because my client don't use Exchange Server.

    Tuesday, March 13, 2012 10:17 AM
  • If your event reciever is running in IIS context then automating office (here: outlook) is not supported nor encouraged. You will have a great deal of pain with supporting this solution over time.

    Disregarding where you run your outlook you do not use connected sharepoint list to show sharepoint calendar inside outlook but manually synchronize those events into default user's calendar. Maybe you would consider simply 'attaching' that calendar list to outlook?

    This way your code would not be needed as client would see all events directly in outlook. Is this solution ok for you?

    Tuesday, March 13, 2012 10:48 AM
  • Yes, I use Connect to Outlook, but this not help for me.

    Because, my client and my Boss want to add event to SharePoint calendar from own/personal Outlook calendar.

    Tuesday, March 13, 2012 10:56 AM
  • Ok, so disregarding that you automate outlook in IIS, here is one of possible solutions to this problem:

    - since this is not a connected sharepoint list, STS* properties will not be present. You have to maintain your own bookkeeping which apointment related to which listitem in sharepoint. Add UserProperty like ListItemId (remember to pass true to add it also to folder level) and in event reciever read Item["ID"] and use DASL to find your corresponding appointmentItem in outlook, like: Items.Find("@SQL=http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/ListItemId = 123") to find item with id 123.

    There are some things that you have to remember - in series you will have MasterSeriesItemId that points to master list item - depending on EventType you will have to remember to either find series appointmentitem or single occurance (existing or create one if needed).

    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:21 AM
    Tuesday, March 13, 2012 11:19 AM
  • Looking at the ID data, it does look like a regular Outlook appointment id (starts with 04).

    Do you see it in Outlook if you select the appointment and then use OutlookSpy (click Item and IMessage buttons)? 


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!

    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:21 AM
    Tuesday, March 13, 2012 5:31 PM