C# 如何检索定期约会

C# 如何检索定期约会,c#,exchangewebservices,C#,Exchangewebservices,我正在使用service.FindItems方法从exchange服务器检索约会,但它不会返回定期约会。它返回定期项目的第一个实例,但此后不再返回,并且在约会中IsRecurring设置为false 代码如下: private void loadUsersAppointments(string user, int rscID) { // Add a search filter that searches on the body or subject. Li

我正在使用service.FindItems方法从exchange服务器检索约会,但它不会返回定期约会。它返回定期项目的第一个实例,但此后不再返回,并且在约会中IsRecurring设置为false

代码如下:

private void loadUsersAppointments(string user, int rscID)
    {
        // Add a search filter that searches on the body or subject.
        List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
        searchFilterCollection.Add(new SearchFilter.IsGreaterThan(AppointmentSchema.Start, DateTime.Today.AddDays(-7)));

        // Create the search filter.
        SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());

        CalendarView V = new CalendarView(DateTime.Today.AddDays(-7), DateTime.Today.AddMonths(1), 1000);
        V.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
        V.Traversal = ItemTraversal.Shallow;

        // Create a view with a page size of 50.
        ItemView view = new ItemView(10000);

        // Identify the Subject and DateTimeReceived properties to return.
        // Indicate that the base property will be the item identifier
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);

        // Order the search results by the DateTimeReceived in descending order.
        view.OrderBy.Add(AppointmentSchema.Start, SortDirection.Descending);

        // Set the traversal to shallow. (Shallow is the default option; other options are Associated and SoftDeleted.)
        view.Traversal = ItemTraversal.Shallow;

        // Send the request to search the Inbox and get the results.
        ExchangeService service = GlobalFunc.ElevateGetBinding();
        service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, user+"@works.local");
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, searchFilter, view);

        List<Item> items = new List<Item>();
        foreach (Microsoft.Exchange.WebServices.Data.Appointment appointment in findResults)
        {
            items.Add(appointment);
        }
        service.LoadPropertiesForItems(items, PropertySet.FirstClassProperties);

        // Process each item.
        foreach (Microsoft.Exchange.WebServices.Data.Appointment myItem in items)
        {
            DevExpress.XtraScheduler.Appointment AddAppt = new DevExpress.XtraScheduler.Appointment();

            try {
                if (myItem.Subject.StartsWith("Advisor Appointment"))
                    AddAppt.LabelId = 8;
                else
                    AddAppt.LabelId = 2;
                AddAppt.Subject = myItem.Subject;
            }
            catch { }
            try
            {

            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            try { AddAppt.Start = myItem.Start; }
            catch { }
            try { AddAppt.Description = myItem.Body; }
            catch { }
            try { AddAppt.End = myItem.End; }
            catch { }
            AddAppt.ResourceId = rscID;




            schStorage.Appointments.Add(AddAppt);
        }
    }
private void loadusersappoints(字符串用户,int-rscID)
{
//添加搜索正文或主题的搜索筛选器。
List searchFilterCollection=新建列表();
searchFilterCollection.Add(新的SearchFilter.isgreater大于(AppointmentSchema.Start,DateTime.Today.AddDays(-7));
//创建搜索过滤器。
SearchFilter SearchFilter=新建SearchFilter.SearchFilterCollection(LogicalOperator.Or,SearchFilterCollection.ToArray());
CalendarView V=新的CalendarView(DateTime.Today.AddDays(-7),DateTime.Today.AddMonths(1),1000);
V.PropertySet=newpropertyset(BasePropertySet.IdOnly,appointschema.Subject,appointschema.Start,appointschema.End);
V.遍历=项遍历。浅;
//创建页面大小为50的视图。
ItemView视图=新的ItemView(10000);
//标识要返回的主题和DateTimeReceived属性。
//指示基本属性将是项标识符
view.PropertySet=newpropertyset(BasePropertySet.IdOnly,appointschema.Subject,appointschema.Start,appointschema.End);
//按DateTimeReceived降序排列搜索结果。
view.OrderBy.Add(appointschema.Start,SortDirection.Descending);
//将遍历设置为浅。(浅是默认选项;其他选项关联并删除。)
view.Traversal=ItemTraversal.Shallow;
//发送请求以搜索收件箱并获取结果。
ExchangeService service=GlobalFunc.ElevateTGetBinding();
service.ImpersonatedUserId=新的ImpersonatedUserId(ConnectingIdType.SmtpAddress,user+“@works.local”);
FindItemsResults findResults=service.FindItems(WellKnownFolderName.Calendar、searchFilter、view);
列表项=新列表();
foreach(findResults中的Microsoft.Exchange.WebServices.Data.Appointment)
{
项目.增加(任命);
}
服务.LoadPropertiesForItems(items,PropertySet.FirstClassProperties);
//处理每个项目。
foreach(项目中的Microsoft.Exchange.WebServices.Data.Appointment myItem)
{
DevExpress.XtraScheduler.Appointment AddAppt=新建DevExpress.XtraScheduler.Appointment();
试一试{
if(myItem.Subject.StartsWith(“顾问任命”))
AddAppt.LabelId=8;
其他的
AddAppt.LabelId=2;
AddAppt.Subject=myItem.Subject;
}
捕获{}
尝试
{
}
catch(Exception ex){MessageBox.Show(ex.Message);}
请尝试{AddAppt.Start=myItem.Start;}
捕获{}
请尝试{AddAppt.Description=myItem.Body;}
捕获{}
请尝试{AddAppt.End=myItem.End;}
捕获{}
AddAppt.ResourceId=rscID;
schStorage.appoints.Add(AddAppt);
}
}
任何想法都将不胜感激


谢谢

您需要使用日历视图来获取定期约会。定期约会的实例不是Exchange数据库中的真实项目。相反,当您查询特定的时间范围时,Exchange会动态创建虚拟项