检索当前Outlook约会 [英] Retrieve current Outlook appointment

查看:232
本文介绍了检索当前Outlook约会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个程序,检查前景约会,基本上我只需要在当前的任命 - 如果当前没有预约,然后就在旁边,甚至previous预约

我想,要做到这一点,我需要使用[限制方法] [1],以限制设置好的约会,然后只需选择其中根据限制参数(例如限制后结束只约会的第一个或最后一个约会当前时间或当前时间开始前只约会)。 我有很多所需要的参数字符串过滤器的麻烦。

一个简单的VB例子(code残端)如下([来源] [2])

  myStart =格式(Date,MM / DD / YYYY HH:MM AMPM)
strRestriction =[开始]< ='&放大器; myStart和放大器; '

限制项集合
设置oResItems = oItems.Restrict(strRestriction)
'分类
oResItems.Sort[开始]
 

然而,试图在C#中做同样的似乎并不奏效。

  //创建Outlook应用程序。
Outlook.Application oApp =新Outlook.Application();

//获取命名空间和登录信息。
// Outlook.NameSpace ONS =(Outlook.NameSpace)oApp.GetNamespace(MAPI);
Outlook.NameSpace ONS = oApp.GetNamespace(MAPI);

//通过使用一个对话框来选择配置文件登录。
oNS.Logon(Missing.Value,Missing.Value,真正的,真实的);

//获取日历文件夹。
Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

//从日历文件夹中获取的项目(约会)集合。
oItems = oCalendar.Items;
oItems.IncludeRecurrences = TRUE;

//这是有问题的区域
字符串过滤器=[开始]< ='+ DateTime.Now.ToString(MM / DD / YYYY HH:MM AMPM)+';
Outlook.Items restrictedItems = oItems.Restrict(过滤器);
//以名单上的最后一个项目 - 应该是当前或下一个约会
restrictedItems.Sort([开始]);
Outlook.AppointmentItem oAppt = restrictedItems.GetLast();


//完成。注销。
oNS.Logoff();
 

首先,我想由于过滤器是一个字符串,日期格式必须是YYYY / MM / DD HH:MM:SS?而我似乎无法找到如何操作[开始],像它解析为一个日期或任何东西的文件(我尝试了各种各样的事情,但没有任何工程)。根据我使用的日期格式,我要么得到错误的任命,否则程序将无法使用GetLast由于不包括所有约会的过滤器。

谷歌能不能帮我了,大家好,我见过的人声称他们得到它的工作的几个例子,但他们要么通过任命(效率太低),或者日期格式循环看起来他们不能值得信赖返回正确的任命(好像是这个家伙social.msdn.microsoft.com/Forums/en-US/vsto/thread/c6a8bd21-6534-43be-b23e-1068651da92e,谁也似乎有硬codeD的日期如果使用DateTime.Now代替。)

更新:我决定我不想浪费更多的时间去工作的限制的角度,所以我目前只是通过像如下所示循环,但对于更有效的code的任何建议都非常欢迎。

 日期时间currentTime的= DateTime.Now;
的foreach(在oItems Outlook.AppointmentItem项)
{
    如果(item.Start&其中; = currentTime的&安培;&安培; item.End.Subtract(新时间跨度(0,10,0))> currentTime的)
    {
        appointmentArrayList.Add(项目);
    }
}
 

解决方案

通过以下找到的信息<一个href="http://www.eggheadcafe.com/software/aspnet/29100666/problem-with-mapifolderitemsrestrict-c-outlook-2003-and-ear.aspx"相对=nofollow>此处,我能够得到它使用的工作YYYY-MM-DD HH:MM的格式字符串的toString呼叫

希望这有助于。

I'm writing a program that checks outlook for appointments, and basically I just need the current appointment - and if no current appointment then just the next or even previous appointment.

I figure to do this I need to use the [restrict method][1] to limit the set of appointments, and then just choose either the first or last appointment depending on the restrict argument (e.g. restrict to only appointments ending after current time, or only appointments starting before current time). I'm having a lot of trouble with the String filter needed as argument.

A simple VB example (code stump) is as follows ([source][2])

myStart = Format(Date, "mm/dd/yyyy hh:mm AMPM")    
strRestriction = "[Start] <= '" & myStart & "'"

'Restrict the Items collection
Set oResItems = oItems.Restrict(strRestriction)
'Sort
oResItems.Sort "[Start]"

However, attempting to do the same in C# doesn't seem to be working.

// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();

// Get the NameSpace and Logon information.
// Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

//Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);

// Get the Calendar folder.
Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

// Get the Items (Appointments) collection from the Calendar folder.
oItems = oCalendar.Items;
oItems.IncludeRecurrences = true;

// THIS IS THE PROBLEM AREA
String filter = "[Start] <= '" + DateTime.Now.ToString("MM/dd/yyyy hh:mm AMPM") + "'";
Outlook.Items restrictedItems = oItems.Restrict(filter);
// Take the last item on the list - should be current or next appointment
restrictedItems.Sort("[Start]");
Outlook.AppointmentItem oAppt = restrictedItems.GetLast();


// Done. Log off.
oNS.Logoff();

First of all, I imagine since the filter is a string, the date format needs to be yyyy/mm/dd HH:mm:ss? And I can't seem to find any documentation on how to manipulate the [Start], like parsing it to a date or something (and I've tried all sorts of things, but nothing works). Depending on the date format I use, I will either get the wrong appointment, or the program will be unable to use GetLast due to the filter excluding all appointments.

Google can't help me anymore guys, I've seen several examples of people claiming they got it to work, but either they loop through the appointments (too inefficient), or the date formats look like they can't be trusted to return the correct appointment (like this guy social.msdn.microsoft.com/Forums/en-US/vsto/thread/c6a8bd21-6534-43be-b23e-1068651da92e , who also seems to have hardcoded the date instead if using DateTime.Now..)

UPDATE: I decided I didn't want to waste any more time trying to work the Restrict angle, so I'm currently just looping through like shown below, but any suggestions for more efficient code are very welcome.

DateTime currentTime = DateTime.Now;
foreach (Outlook.AppointmentItem item in oItems)
{
    if (item.Start <= currentTime && item.End.Subtract(new TimeSpan(0, 10, 0)) > currentTime)
    {
        appointmentArrayList.Add(item);
    }
}

解决方案

By following the information found here, I was able to get it to work using "yyyy-MM-dd HH:mm" as the format string for the toString call.

Hope this helps.

这篇关于检索当前Outlook约会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆