Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

Commented Unassigned: NetOffice.OutlookAPI.Items.Sort() is erroring with an Out of Memory exception. [21697]

$
0
0
When reading calendar appointments from Outlook, there's an option called "IncludeRecurrences" that should add all future recurrences to the list of items. For example: if I have a recurring appointment that happens every Wednesday, when my list of appointments return, I should see a future entries for my Wednesday appointment.

This works great using the Office.Interop, but when I switch my code to NetOffice, I receive an error message after I set IncludeRecurrences to true, and then try and Sort. The Sort() method does not work correctly, and errors out saying "Exception of type 'System.OutOfMemoryException' was thrown."

Here is the stack trace:
((System.Exception)((new System.Linq.SystemCore_EnumerableDebugView<object>(OutlookItems)).Items)).StackTrace at NetOffice.OutlookApi._Items.d__7.MoveNext() at NetOffice.OutlookApi._Items.d__0.MoveNext() at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()

Would it be possible to make this work similar to the Office.Interop?

Here is my code:

public List<Appointment> GetAppointmentsInRange()
{
var result = new List<Appointment>();

Items OutlookItems = outlookCalendar.Items as Items;
OutlookItems.IncludeRecurrences = true;
OutlookItems.Sort("[Start]");

if (OutlookItems != null)
{
DateTime min = DateTime.Now.AddDays(-1);
DateTime max = DateTime.Now.AddDays(+30);

string filter = "[End] >= '" + min + "' AND [Start] < '" + max + "'";

var filteredAppoinments = OutlookItems.Restrict(filter);
foreach (AppointmentItem ai in filteredAppoinments)
{
result.Add(GetOutlookAppointment(ai));
}
}
return result;
}
Comments: ** Comment from web user: SebastianDotNet **


this is the common way for example:
(https://msdn.microsoft.com/en-us/en-us/library/office/ff860338.aspx)

object item = inboxFolder.Items.GetFirst();
while (null != item)
{
item = inboxFolder.Items.GetNext();
}

nice to know, the NetOffice custom enumerator:
[from NetOffice metadata]
public class _Items
{
//
// Zusammenfassung:
// SupportByVersionAttribute Outlook, 9,10,11,12,14,15 This is a custom enumerator
// from NetOffice
[CustomEnumerator]
public IEnumerator<object> GetEnumerator();
}

*Sebastian


Viewing all articles
Browse latest Browse all 1741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>