none
vsto create recurrence exception "cannot save this item." RRS feed

  • Question

  • Hi,

    When I am creating a recurrence exception, I am getting an exception when I am saving the new instance of exception. Following is the code I have written. I am following the code illustrated at Here. Not sure what I am missing, please help.


    if (myInstance != null)
    {
    	myInstance.Subject = exAppoinment.Title;
    	myInstance.Save();
    
    	Outlook.RecurrencePattern newPattern = oNewItem.GetRecurrencePattern();
    	var cnt = newPattern.Exceptions.Count;
    	Outlook.Exception myException = (newPattern.Exceptions.Count > 0 ? newPattern.Exceptions[newPattern.Exceptions.Count] :
    		 newPattern.Exceptions[1]);
    	if (myException != null)
    	{
    		Outlook.AppointmentItem myNewInstance =
    			myException.AppointmentItem;
    		myNewInstance.Start = stdt;
    		myNewInstance.End = endt;
    		myNewInstance.Body = exAppoinment.Body;
    		myNewInstance.UserProperties.Add("SCSID", Outlook.OlUserPropertyType.olInteger, false).Value = exAppoinment.SmartCalenderId;
    		myNewInstance.Save(); //HERE I AM GETTING THE EXCEPTION
    
    		ReleaseComObject(myNewInstance);
    		myNewInstance = null;
    	}
    
    	oNewItem.Save();
    	ReleaseComObject(myException);
    	myException = null;
    
    	ReleaseComObject(newPattern);
    	newPattern = null;
    
    	ReleaseComObject(myInstance);
    	myInstance = null;
    }

    Saturday, March 18, 2017 1:27 PM

All replies

  • Hello Pradeep,

    Unlike most of the other Microsoft Outlook objects, the Exception object is a read-only object. This means that you cannot create an Exception object but, rather, the object is created when a property of an AppointmentItem is altered. For example, if you change the Start property of one AppointmentItem, you have created an Exception in AppointmentItem.RecurrencePattern.Exceptions.

    Try to use the GetOccurrence method of the RecurrencePattern class instead.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Sunday, March 19, 2017 1:31 PM