none
Help with outlook MeetingItem send update. RRS feed

  • Question

  • Hi all,

    I have a problem on saving and sending an update of a meeting item.

    I'll try and explain what im trying to achieve, i have a recurring meeting that goes daily, now after the meeting is already made the user wants to change one occurrence to a different hour, now what im doing is when i create the recurrent meeting i add text to the message body of all the occurrences and when a user changes one occurrence i delete ALL the text I inserted to that specific occurrence and update the series appointment item with deleting the text of that occurrence.

    My problem is as follows, my logic works fine, i succeed in adding and removing the text, i succeed in updating the occurrence changed and succeed in saving those changes, i also succeed in updating the series appointment item but i cant seem to succeed in saving the text changed and preferably send a notice that this is changed.

    Can you please help with how to do that? if you need my code i can post it here for you to review it.

    Im using VS2010 and outlook 2010 with C#.

    Thanks in advance for any help given.

    Ram.


    • Edited by Ram Amos Sunday, May 6, 2012 10:54 AM
    Sunday, May 6, 2012 10:52 AM

Answers

  • before calling masteritem.getinspector, invoke masteitem.Display so window for that item will be shown. Then you can see how your code changes text inside that master item. Later call save and send as usually and see if changes are sent/persisted.
    • Marked as answer by Ram Amos Wednesday, May 9, 2012 11:04 AM
    Wednesday, May 9, 2012 10:07 AM

All replies

  • i cannot check it myself right now but cou;ld you verify if changing meeting item body acxtually creates exception or not? i;m sure it does so with subject, location and start/end time, but i;m not so sure with item body. If it will turn out that changing body does not create exception then you are out of luck - outlook will not send such update to participants - you will need to make exception of that single occurence (by changing one of the properties mentioned above).

    Sunday, May 6, 2012 2:45 PM
  • It is in fact create an exception from the changed occurrence, that's how i know which occurrence i changed from my code and then remove the addition to the body i've inserted when i create the recurrent meeting in the first place, i can save the changes done to that occurrence no problem, but when i try to save the series it wont save or send the change and i dont understand why.
    Monday, May 7, 2012 6:17 AM
  • A recurring series consists of a master appointment that's used to calculate the entire series. Unless there are exceptions or deleted instances that's it, there is nothing else.
     
    If you change something in an exception item it will only be changed on that instance.
     
    If you want to change the master then from the RecurrencePattern object use the Parent property to get to the master appointment.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "Ram Amos" <=?utf-8?B?UmFtIEFtb3M=?=> wrote in message news:3042f598-866d-45b9-8cf0-33d3822c7977...
    It is in fact create an exception from the changed occurrence, that's how i know which occurrence i changed from my code and then remove the addition to the body i've inserted when i create the recurrent meeting in the first place, i can save the changes done to that occurrence no problem, but when i try to save the series it wont save or send the change and i dont understand why.

    Ken Slovak MVP - Outlook
    Monday, May 7, 2012 3:49 PM
  • as an addition to what Ken said - if you have recurring series and _all_ occurances are exceptions then making any change to master series item will not be shown anywhere in UI, since all items will be ovelayed with exception items (user would have to explicitly double click one item and choose to see master series item).

    If we misunderstood your problem, please provide us with steps to reproduce problem.

    Monday, May 7, 2012 6:36 PM
  • I know that, Let me explain again what im doing so I will be clearer, when i create a new recurrent meeting of say 10 occurrences on creation i list in the every occurrence and the master body where they have a room and which room it is and where they dont have a room.

    Now if for some reason the user wants to change one of the occurrences to some other time and i have a room booked for that occurrence what im doing is cancel the room and i delete all the text i've added to the body at the time of creation, also im trying to update the master appointment and delete the text where it relates to the occurrence that i just changed cause if i changed the time then the information there is no longer correct and i want to delete it, in the business side everything im doing is happening also i manage to save the changes in the occurrence where i changed the time so it doesnt tell me to save changes when i open the occurrence.

    problem is that after i updated the master appointment it doesnt save the changes i've made and request me to save and send update, and i want to do that from code.

    let me place here some of my code.

    MeetingItem item = (Item as MeetingItem);
    
                if (item != null)
                {
                    // Get current item as AppointmentItem (MeetingItem does not have a MeetingStatus property).
                    AppointmentItem appointmentItem = (Item as MeetingItem).GetAssociatedAppointment(false);
                    if (appointmentItem != null)
                    {
                        try
                        {
                            // Cancelling Meeting
                            if(item.Class == OlObjectClass.olMeetingCancellation)
                            {
                                OutlookItemLogic.CancelReservationInOutlookItem(item);
                            }
                            else // Updating Meeting
                            {
                                if (appointmentItem.IsRecurring == false)
                                {
                                    // Single
                                    Reservation reservation = OutlookItemLogic.GetReservationDetails(appointmentItem);
                                    if (reservation != null)
                                    {
                                        if (OutlookItemLogic.CheckIfReservationIsOutOfSync(appointmentItem, reservation))
                                        {
                                            OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
                                        }
                                    }
                                }
                                else
                                {
                                    // Recurrent
                                    AppointmentItem master = null;
    
                                    if (appointmentItem.Parent as AppointmentItem != null)
                                        master = appointmentItem.Parent as AppointmentItem;
                                    else
                                        master = appointmentItem;
    
                                    master.Save();
    
                                    RecurrentReservationWithTicks recReservation = OutlookItemLogic.GetRecurrentReservationDetails(master);
                                    if (recReservation != null)
                                    {
                                        // Occurrence
                                        if (appointmentItem.RecurrenceState != OlRecurrenceState.olApptMaster)
                                        {
                                            Reservation reservation =
                                                recReservation.Reservations.Where(p => p.Date == appointmentItem.Start.Date).SingleOrDefault();
    
                                            if (reservation != null)
                                            {
                                                // Restore time (Lost in Deserialization)
                                                reservation.StartTime = recReservation.StartTime;
                                                reservation.EndTime = recReservation.EndTime;
    
                                                if (OutlookItemLogic.CheckIfReservationIsOutOfSync(appointmentItem, reservation))
                                                {
                                                    OutlookItemLogic.FormatWordDoc(item, reservation);
                                                    OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);                                                
                                                }
                                            }
                                            item.Save();
                                            appointmentItem = null;
                                        }
                                        // Series
                                        else
                                        {
                                            if (OutlookItemLogic.CheckIfRecurrentReservationIsOutOfSync(appointmentItem, recReservation))
                                            {
                                                OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
                                            }
                                        }
    
                                    }
                                }
                            }
                        }

    And here is the FormatWordDoc  method where i do most of my business things.

     public static void FormatWordDoc(MeetingItem mtng, Reservation res)
            {
                AppointmentItem appt = null;
                Microsoft.Office.Interop.Outlook.RecurrencePattern recPattern = null;
                AppointmentItem masterAppt = null;
                try
                {
                    appt = mtng.GetAssociatedAppointment(false);
                    //mtng.Save(); //Save the meeting item
    
                    //Get recurrent patter from the appointment
                    recPattern = appt.GetRecurrencePattern();
                    appt.Save();
                    // get the interval of the recurrent appointment
                    int recType = recPattern.Interval;
    
                    //Get the location of the appointment
                    LocationPreferences lp = GetCRSLocation(appt);
    
                    if (recPattern.Exceptions.Count > 0)
                    {
                        foreach (Microsoft.Office.Interop.Outlook.Exception item in recPattern.Exceptions)
                        {
                            if (!item.Deleted && item.AppointmentItem.Body.Contains(CRS_STRING_PLACEHOLDER + " Valid Reservations Start " + CRS_STRING_PLACEHOLDER))
                            {
                                appt = item.AppointmentItem;
                                //Remove the text in that occurrence
                                RemoveText(ref appt);
                            }
                        }
                    }
                    masterAppt = (AppointmentItem)appt.Parent;
    
                    //replace text in series appointment.
                    ReplaceText(res, lp, ref masterAppt);
                   
                }
                catch
                {
    
                }
                finally
                {
                    masterAppt.Save();
                    Marshal.ReleaseComObject(recPattern);
                    Marshal.ReleaseComObject(masterAppt);
                    Marshal.ReleaseComObject(appt);
                    recPattern = null;
                    masterAppt = null;
                    appt = null;
                }

    Thanks for you answers and help.

    Tuesday, May 8, 2012 6:26 AM
  • let us start with basics and we will see when it will start working:

    1. for future reference - occurence means single event that is not yet an exception. So please next time when you describe what you do, use proper term because now i'm somewhat confused if you actually do make every occurence an exception on series creation or not.

    2. appointments in outlook are very sensitive in conflict resolution and multiple references - i see that you grab hold onto master item in main code and a second one in FormatWordDoc without actually releasing first variable beforehand - please change this code to pass master as an parameter to function and do not grab it second time. Also remember th call Marshal.ReleaseComObject on appointments, recurrences, etc. as soon as you're done with them, it is very crucial for calendar items in outlook.

    3. you are looking for appointment info in your storage by searching for current appointment.Start property - this will not work if user dragged and dropped appointment to new timeslot (which opened inspector for that appointment but with new Start time values). If your occurances are really exceptions, you should use appointmnet.GetRecurrencePattern().Exceptions collection to look by .OriginalDate property which you should also store as this is the only thing that will not change.

    Tuesday, May 8, 2012 9:18 AM
  • Thank you for your reply, i will be more clear with my terminology in the future.

    I added the Marshal.ReleaseComObject on every and all items that i create, and i send ref to items instead of sending the items themselves thank you for pointing that out.

    Now i know i'm missing something and im not sure what, all i need to do is when im done with changing exception body text and master body text i want to save both of them, i manage the saving of the exceptions but the master isnt saved for some odd reason, after i add in the master.Save() i open the master appointment and when i try to close it outlook asks me to save and send update, but i already did that through code,

    if you need me to post my code changes i will.

    Tuesday, May 8, 2012 10:21 AM
  • yes, post your new code
    Tuesday, May 8, 2012 10:39 AM
  •  public static void FormatWordDoc(MeetingItem mtng, Reservation res, ref AppointmentItem masterAppt)
            {
                AppointmentItem appt = null;
                Microsoft.Office.Interop.Outlook.RecurrencePattern recPattern = null;
                try
                {
                    appt = mtng.GetAssociatedAppointment(false);
                    //mtng.Save(); //Save the meeting item
    
                    //Get recurrent patter from the appointment
                    recPattern = appt.GetRecurrencePattern();
                    appt.Save();
                    // get the interval of the recurrent appointment
                    int recType = recPattern.Interval;
    
                    //Get the location of the appointment
                    LocationPreferences lp = GetCRSLocation(appt);
    
                    if (recPattern.Exceptions.Count > 0)
                    {
                        foreach (Microsoft.Office.Interop.Outlook.Exception item in recPattern.Exceptions)
                        {
                            if (!item.Deleted && item.AppointmentItem.Body.Contains(CRS_STRING_PLACEHOLDER + " Valid Reservations Start " + CRS_STRING_PLACEHOLDER))
                            {
                                appt = item.AppointmentItem;
                                //Remove the text in that occurrence
                                RemoveText(ref appt);
                            }
                        }
                    }
                    //masterAppt = (AppointmentItem)appt.Parent;
    
                    //replace text in series appointment.
                    ReplaceText(res, lp, ref masterAppt);
                   
                }
                catch
                {
    
                }
                finally
                {
                    
                    Marshal.ReleaseComObject(recPattern);
                    Marshal.ReleaseComObject(appt);
                    recPattern = null;
                    appt = null;
                }

    MeetingItem item = (Item as MeetingItem);
    
                if (item != null)
                {
                    // Get current item as AppointmentItem (MeetingItem does not have a MeetingStatus property).
                    AppointmentItem appointmentItem = (Item as MeetingItem).GetAssociatedAppointment(false);
                    if (appointmentItem != null)
                    {
                        try
                        {
                            // Cancelling Meeting
                            if(item.Class == OlObjectClass.olMeetingCancellation)
                            {
                                OutlookItemLogic.CancelReservationInOutlookItem(item);
                            }
                            else // Updating Meeting
                            {
                                if (appointmentItem.IsRecurring == false)
                                {
                                    // Single
                                    Reservation reservation = OutlookItemLogic.GetReservationDetails(appointmentItem);
                                    if (reservation != null)
                                    {
                                        if (OutlookItemLogic.CheckIfReservationIsOutOfSync(appointmentItem, reservation))
                                        {
                                            OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
                                        }
                                    }
                                }
                                else
                                {
                                    // Recurrent
                                    AppointmentItem master = null;
    
                                    if (appointmentItem.Parent as AppointmentItem != null)
                                        master = appointmentItem.Parent as AppointmentItem;
                                    else
                                        master = appointmentItem;
    
                                    master.Save();
    
                                    RecurrentReservationWithTicks recReservation = OutlookItemLogic.GetRecurrentReservationDetails(master);
                                    if (recReservation != null)
                                    {
                                        // Occurrence
                                        if (appointmentItem.RecurrenceState != OlRecurrenceState.olApptMaster)
                                        {
                                            Reservation reservation =
                                                recReservation.Reservations.Where(p => p.Date == appointmentItem.Start.Date).SingleOrDefault();
    
                                            if (reservation != null)
                                            {
                                                // Restore time (Lost in Deserialization)
                                                reservation.StartTime = recReservation.StartTime;
                                                reservation.EndTime = recReservation.EndTime;
    
                                                if (OutlookItemLogic.CheckIfReservationIsOutOfSync(appointmentItem, reservation))
                                                {
                                                    OutlookItemLogic.FormatWordDoc(item, reservation, ref master);
                                                    OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
    
                                                    master.Save();
                                                    master.Send();
                                                    Marshal.ReleaseComObject(master);
                                                    master = null;
                                                }
                                            }
                                            item.Save();
                                            Marshal.ReleaseComObject(item);
                                            Marshal.ReleaseComObject(appointmentItem);
                                            appointmentItem = null;
                                        }
                                        // Series
                                        else
                                        {
                                            if (OutlookItemLogic.CheckIfRecurrentReservationIsOutOfSync(appointmentItem, recReservation))
                                            {
                                                OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
                                            }
                                        }
    
                                    }
                                }
                            }
                        }

    Now it is worse, when i do master.Save() and then master.Send() it just discard all the changes i've made.

    Tuesday, May 8, 2012 10:49 AM
  • hmm, code

    if (appointmentItem.Parent as AppointmentItem != null)
                                        master
    = appointmentItem.Parent as AppointmentItem;

    creates 2 variables for master item (first one is invisible since you do not store result anywhere). Please change it to something like:

    var master = appointmentItem.Parent as AppointmentItem;

    if(master != null)

    and do the same for AppointmentItem on top of your second code block

    MeetingItem item = (Item as MeetingItem);

               
    if (item != null)
               
    {
                   
    // Get current item as AppointmentItem (MeetingItem does not have a MeetingStatus property).
                   
    AppointmentItem appointmentItem = (Item as MeetingItem).GetAssociatedAppointment(false);

    Tuesday, May 8, 2012 11:07 AM
  • OK, i have changed the code as you suggested, thank you for pointing that out, i have never thought at that as creating a variable but from now on i will keep that in mind.

    problem is it is still not solve my problem, i can see my changes being made but when i get to the master.Save() and master.Send() it is like it discards all the changes i've made to the exception and the master appointment and just revert back to its original state, any idea why it is like that?

    Tuesday, May 8, 2012 11:27 AM
  • ok, let's start with one problem - master item.

    1. Comment out all code that is not necessary for this code path - cancellation path, not recurring item path, etc.

    2. comment out initial call to save on master item

    3. comment out code that manipulates single occurence, iteration of exceptions, etc. leave only replaceText function and call to save and send on master item afterwards.

    Does it still discard your master changes?

    Tuesday, May 8, 2012 11:57 AM
  • Ok, so i commented out everything that relates to non appointment/meeting item also i commented out all occurrence and exception related code, and still the master item would return to its original state, then i commented out master.Save() and master.Send() and then the master item would stay as i changed its body but when i opened the series and i saw the changes i've made, and i just wanted to to close the window outlook forces me to save and send update which does the job but i want to do just that out of my code and am not able to for some weird reason.
    Tuesday, May 8, 2012 12:13 PM
  • do not worry, it is possible to do it from code, we just have to find out what is causing the problem.

    Now additionally comment out everything below grabbing master item from appointment.Parent

    and add following code:

    master.Body = "hello world";

    master.Save();

    master.Send();

    Marshal.FinalReleaseComObject(master);

    return;

    do changes in master item get sent?

    Tuesday, May 8, 2012 12:24 PM
  • Hmmm, interesting, it does save the changes and is not prompting me for anything, thats great, now what?

    what did i do wrong?

    Tuesday, May 8, 2012 12:30 PM
  • hard to tell since you did not show all the code. Start from code that is now working and simply move it into proper 'if' block. Uncomment everything besides FormatWordDoc and CancelReservationInOutlookItem. Check if it still works.
    Tuesday, May 8, 2012 12:52 PM
  • That's exactly what im doing, I have posted the FormatWordDoc code the only thing that i didnt post is the ReplaceText method, so here it is.

    private static void ReplaceText(Reservation res, LocationPreferences lp, ref AppointmentItem masterAppt)
            {
                Document wordDoc = null;
                Range rng = null;
                try
                {
                    object missing = System.Reflection.Missing.Value;
                    wordDoc = (Document)masterAppt.GetInspector.WordEditor;
                    Object start = 0; Object end = 0;
                    rng = wordDoc.Range(ref start, ref end);
                    rng.Font.Size = 9;
                    rng.Font.Bold = 0;
                    rng.Font.Underline = 0;
                    rng.Font.Italic = 0;
    
                    string body = wordDoc.Content.FormattedText.Text;
    
                    string appointmentBodyString = string.Empty;
                     
                    rng.SetRange(0, 0);
                    rng.Find.Text = CRS_STRING_PLACEHOLDER + " Valid Reservations Start " + CRS_STRING_PLACEHOLDER;
                    rng.Find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    int rngStart = rng.Start;
    
                    rng.SetRange(0, 0);
                    rng.Find.Text = CRS_STRING_PLACEHOLDER + " Invalid Reservations End " + CRS_STRING_PLACEHOLDER;
                    rng.Find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    int rngEnd = rng.End;
    
                    rng.SetRange(rngStart, rngEnd);
                    body = rng.Text;
    
                    //INSERTION POINT AT START OF BODY
                    
                    int endOfRange = wordDoc.Characters.Count;
    
                    //DELETE PREVIOUS SEARCH
                    wordDoc.Content.Find.ClearFormatting();
                    wordDoc.Content.Find.Replacement.ClearFormatting();
    
                    string findText = string.Format("Date: {3}, Site: {0}, Building: {1}, Room: {2}", lp.Site.SiteName, res.Room.BuildingName,
                        res.Room.RoomName, res.Date.ToShortDateString());
    
                    body = body.Replace(findText, null);
                    rng.Delete(ref missing, ref missing);
                    wordDoc.Content.InsertAfter(body);
    
                }
                catch 
                {
                    
                }
            }

    Tuesday, May 8, 2012 12:56 PM
  • you should get hold onto Inspector object and after you finish your word api fiddling, call Close(SaveChanges) on it and Marshal.ReleseComObject.

    wordDoc = (Document)masterAppt.GetInspector.WordEditor;

    Tuesday, May 8, 2012 1:28 PM
  • I know you're spoon feeding me here but damn it i cant figure it out, i did what you suggested(could be in the wrong way) but it is still discards the changes, here's the revised code.

    private static void ReplaceText(Reservation res, LocationPreferences lp, ref AppointmentItem masterAppt)
            {
                Document wordDoc = null;
                Range rng = null;
                Inspector insp = null;
                try
                {
                    object missing = System.Reflection.Missing.Value;
                    insp = masterAppt.GetInspector;
                    wordDoc = (Document)insp.WordEditor;
                    Object start = 0; Object end = 0;
                    rng = wordDoc.Range(ref start, ref end);
                    rng.Font.Size = 9;
                    rng.Font.Bold = 0;
                    rng.Font.Underline = 0;
                    rng.Font.Italic = 0;
    
                    string body = wordDoc.Content.FormattedText.Text;
    
                    string appointmentBodyString = string.Empty;
                     
                    rng.SetRange(0, 0);
                    rng.Find.Text = CRS_STRING_PLACEHOLDER + " Valid Reservations Start " + CRS_STRING_PLACEHOLDER;
                    rng.Find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    int rngStart = rng.Start;
    
                    rng.SetRange(0, 0);
                    rng.Find.Text = CRS_STRING_PLACEHOLDER + " Invalid Reservations End " + CRS_STRING_PLACEHOLDER;
                    rng.Find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                    int rngEnd = rng.End;
    
                    rng.SetRange(rngStart, rngEnd);
                    body = rng.Text;
    
                    //INSERTION POINT AT START OF BODY
                    
                    int endOfRange = wordDoc.Characters.Count;
    
                    //DELETE PREVIOUS SEARCH
                    wordDoc.Content.Find.ClearFormatting();
                    wordDoc.Content.Find.Replacement.ClearFormatting();
    
                    string findText = string.Format("Date: {3}, Site: {0}, Building: {1}, Room: {2}", lp.Site.SiteName, res.Room.BuildingName,
                        res.Room.RoomName, res.Date.ToShortDateString());
    
                    body = body.Replace(findText, null);
                    rng.Delete(ref missing, ref missing);
                    wordDoc.Content.InsertAfter(body);
    
                }
                catch 
                {
                    
                }
                insp.Close(OlInspectorClose.olSave);
                Marshal.ReleaseComObject(insp);
                Marshal.ReleaseComObject(wordDoc);
                Marshal.ReleaseComObject(rng);
                rng = null;
                wordDoc = null;
            }

    Added an inspector object from it i take the Document then i change what needs to be changed then i Inspector.Close() and then i COM release it.

    Tuesday, May 8, 2012 1:40 PM
  • so with FormatWordDoc function both master and exception items get their changes discarded? I would go back to our methodology with commenting out parts of code and see when it starts to work. I see no evident bug in your code right now.
    Tuesday, May 8, 2012 2:09 PM
  • My occurrence handling as well as my exception handling are both commented out, so all im doing now is handling master appointment, for some reason the insp.Close() is doing the job correctly and saving and closing the window like it supposed to but the changes are discarded, this is really strange.

    Any way i can contact you in a more effective way?

    Tuesday, May 8, 2012 2:17 PM
  • Im 100% sure that when i call  insp.Close(OlInspectorClose.olSave);  and       Marshal.ReleaseComObject(insp);
    All changes are discarded, what i did to check this is before every change that i make to the body i insert it to a string and see what changed.

    first string is before the ReplaceText method which shows the text havnt been changed at all, the next string i check is inside the ReplaceText method just after the wordDoc.Content.InsertAfter(body);
    and indeed it applies the changes perfectly the last string i check is right after the ReplaceText method which shows that after i closed and released the inspector all my changes are discarded. 
    Tuesday, May 8, 2012 2:24 PM
  • There are a few things you can try.
     
    First, you are creating various invisible objects that are only released when the code is out of scope and the garbage collector eventually runs. For example:
     
    wordDoc = (Document)masterAppt.GetInspector.WordEditor;
    That is creating an invisible Inspector object that you cannot explicitly release. Don't use compound dot operators:
     
    Outlook.Inspector insp = masterAppt.GetInspector;
    wordDoc = (Document)insp.WordEditor;
    That way you can explicitly release all of your objects.
     
    Where your test worked you were doing something like this:
     

        master.Body = "hello world";

        master.Save();

        master.Send();

        Marshal.FinalReleaseComObject(master);

    In that case you were working directly on the Body of the master appointment, rather than a Document object. Does it work better if you were to do string processing on the existing Body retrieved as a string value, then setting the Body property to your revised body string?

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    Reminder Manager, Extended Reminders, Attachment Options
    http://www.slovaktech.com/products.htm
     
     
    "Ram Amos" <=?utf-8?B?UmFtIEFtb3M=?=> wrote in message news:6a92023d-f0e4-4571-864e-0da198651aad...
    Im 100% sure that when i call  insp.Close(OlInspectorClose.olSave);  and       Marshal.ReleaseComObject(insp);
    All changes are discarded, what i did to check this is before every change that i make to the body i insert it to a string and see what changed.

    first string is before the ReplaceText method which shows the text havnt been changed at all, the next string i check is inside the ReplaceText method just after the wordDoc.Content.InsertAfter(body);
    and indeed it applies the changes perfectly the last string i check is right after the ReplaceText method which shows that after i closed and released the inspector all my changes are discarded. 

    Ken Slovak MVP - Outlook
    Tuesday, May 8, 2012 2:52 PM
  • it looks like there is something other holding reference to master appointment and outlook on flushing changes discovers conflict and silently decides that your changes should be the victim of conflict resolution. But i may be wrong. Do you have somewhere in other window/inspector open that master item for series?
    Tuesday, May 8, 2012 2:54 PM
  • Problem is if i use the body directly i screw up all the formatting of the users body and i want to avoid that, that's why i work on a Document, let me show you something that might help figure this out.

    string text = masterAppt.Body; //when checking this string i get the original text that is untouched ReplaceText(res, lp, ref masterAppt); //in here i have another string that when i check after string processing everything

    is in order.

    text = masterAppt.Body;//when i look here again i get the same result as the first string.

    I really dont know why, maybe my fiddling with the Document object is somehow wrong, can you please take a look at it and see if you can see anything that is in fact wrong?

    It should have worked but im sure im missing something small that prevents me from completing this.

    Tuesday, May 8, 2012 3:00 PM
  • if you leave erevything as-is but replace Replacetext function to simply insert "hello world" through item.Body property - does it start to work? are updates sent?

    Tuesday, May 8, 2012 6:07 PM
  • Yes when i comment out the ReplaceText method with item.body = hello world it saves the changes. Im guessing im doing something wrong with my text fiddling but what?
    Wednesday, May 9, 2012 5:50 AM
  • i'm very weak with word api, maybe someone better could chime in on this. But in the meantime try to determine which line causes error, like this:

    - comment out everything below wordDoc = (Document)insp.WordEditor; and simply add new line by wordDoc.Content.InsertAfter("hello world");

    does it get discarded or sent? if it works, uncomment few lines more and try again



    Wednesday, May 9, 2012 7:05 AM
  • If i use the master.Text = "hello world"; then the changes persists but if i use wordDoc.Content.InsertAfter(body); the changes are discarded for some reason, im now trying to do this with the Range object and see if that will take me anywhere.
    Wednesday, May 9, 2012 7:22 AM
  • The changes i make inside the wordDoc dont get saved in the master appointment and i cant figure out why, maybe i need to somehow insert back the changed document to the master appointment?
    Wednesday, May 9, 2012 9:18 AM
  • try maybe something along the lines:

    var wordDoc = (Document)inspector.WordEditor;
    var selection = wordDoc.Windows.get_Item(1).Selection;
    selection.Move(WdUnits.wdStory, 1);
    selection.TypeText("hello world");

    does this get persisted?
    Wednesday, May 9, 2012 9:18 AM
  • No, everything i change through the Document is not getting saved, only things i change directly through master.body get saved.

    how would i get about doing this through master.body and still save the style of the user? maybe that will be easier cause this is driving my nuts, i've watched like every piece of code on the web about this and all of them say i do this correctly.

    Wednesday, May 9, 2012 9:36 AM
  • try to actually open in window(inspector) master item, before editing using word api - item.Display
    Wednesday, May 9, 2012 9:54 AM
  • can you please explain a little further on this im not familiar with this.
    Wednesday, May 9, 2012 10:01 AM
  • before calling masteritem.getinspector, invoke masteitem.Display so window for that item will be shown. Then you can see how your code changes text inside that master item. Later call save and send as usually and see if changes are sent/persisted.
    • Marked as answer by Ram Amos Wednesday, May 9, 2012 11:04 AM
    Wednesday, May 9, 2012 10:07 AM
  • Hi Man you wont believe this, when i added master.Display() and ran the same code i ran up till now, it did save the changes if i comment out that line then it wont save anything, how in the hell is the Display() related to this is beyond my understanding, only thing i can think of is giving focus, but i tried that earlier with master.Activate() which gives focus and it didnt work.

    Anyways, i cant thank you enough for this really 1000 thanks and best wishes.

    Wednesday, May 9, 2012 10:20 AM
  • glad i could help :-) If you can live with showing window for editing item then i think problem is solved. If so, please mark an answer so thread will be closed.

    Wednesday, May 9, 2012 10:34 AM
  • Reservation reservation = OutlookItemLogic.GetReservationDetails(appointmentItem);

    Iam Trying to use this.But it is not accepting in my code.

    what reference i need to use?

    Thanks in advance for any help.

    Aditya

    Thursday, February 14, 2013 7:09 AM
  • what is a reservation and what this has to to with this thread?
    Thursday, February 14, 2013 7:14 AM
  • MeetingItem item = (Item as MeetingItem);

                if (item != null)
                {
                    // Get current item as AppointmentItem (MeetingItem does not have a MeetingStatus property).
                    AppointmentItem appointmentItem = (Item as MeetingItem).GetAssociatedAppointment(false);
                    if (appointmentItem != null)
                    {
                        try
                        {
                            // Cancelling Meeting
                            if(item.Class == OlObjectClass.olMeetingCancellation)
                            {
                                OutlookItemLogic.CancelReservationInOutlookItem(item);
                            }
                            else // Updating Meeting
                            {
                                if (appointmentItem.IsRecurring == false)
                                {
                                    // Single
                                    Reservation reservation = OutlookItemLogic.GetReservationDetails(appointmentItem);
                                    if (reservation != null)
                                    {
                                        if (OutlookItemLogic.CheckIfReservationIsOutOfSync(appointmentItem, reservation))
                                        {
                                            OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
                                        }
                                    }
                                }
                                else
                                {
                                    // Recurrent
                                    AppointmentItem master = null;

                                    if (appointmentItem.Parent as AppointmentItem != null)
                                        master = appointmentItem.Parent as AppointmentItem;
                                    else
                                        master = appointmentItem;

                                    master.Save();

                                    RecurrentReservationWithTicks recReservation = OutlookItemLogic.GetRecurrentReservationDetails(master);
                                    if (recReservation != null)
                                    {
                                        // Occurrence
                                        if (appointmentItem.RecurrenceState != OlRecurrenceState.olApptMaster)
                                        {
                                            Reservation reservation =
                                                recReservation.Reservations.Where(p => p.Date == appointmentItem.Start.Date).SingleOrDefault();

                                            if (reservation != null)
                                            {
                                                // Restore time (Lost in Deserialization)
                                                reservation.StartTime = recReservation.StartTime;
                                                reservation.EndTime = recReservation.EndTime;

                                                if (OutlookItemLogic.CheckIfReservationIsOutOfSync(appointmentItem, reservation))
                                                {
                                                    OutlookItemLogic.FormatWordDoc(item, reservation);
                                                    OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);                                               
                                                }
                                            }
                                            item.Save();
                                            appointmentItem = null;
                                        }
                                        // Series
                                        else
                                        {
                                            if (OutlookItemLogic.CheckIfRecurrentReservationIsOutOfSync(appointmentItem, recReservation))
                                            {
                                                OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
                                            }
                                        }

                                    }
                                }
                            }
                        }


    Thanks for you answers and help.

    In this code for update the meeting

    Reservation reservation = OutlookItemLogic.GetReservationDetails(appointmentItem);

    this code hasbeen used.In this code what is Reservation?

    Thursday, February 14, 2013 7:29 AM
  • Reservation is not a class from OOM. This is your own custom code.

    Thursday, February 14, 2013 8:22 AM
  •  if (OutlookItemLogic.CheckIfRecurrentReservationIsOutOfSync(appointmentItem, recReservation))
     
    {
            
    OutlookItemLogic.CancelReservationInOutlookItem(appointmentItem);
     
    }
    Is this code also custom?

    Thursday, February 14, 2013 8:37 AM
  • this is your code, you should know this. When in doubt see where class is defined - if in one of PIA assembly then this is MS code, otherwise your own custom one.
    Thursday, February 14, 2013 9:06 AM