使用Managed API的GetItem示例 [英] GetItem sample using the Managed API

查看:68
本文介绍了使用Managed API的GetItem示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个finditem函数,它返回除了body之外我需要的所有东西。我意识到我需要运行一个GetItem函数来获取正文。我找不到在VB中使用托管API的示例代码。任何人都有VB中的代码来运行针对托管API的GetItem。

这是我的代码的第一部分使用查找项。




公共 功能 GetEventList( ByVal StartTime 作为 DateTime, ByVal EndTime 正如 DateTime) As 列表( CalendarEvent)



< span style ="font-size:x-small; color:#0000ff"> Dim eventList 作为 列表( CalendarEvent)= 列表( CalendarEvent)



尝试





Dim service 作为 ExchangeService = ExchangeService(ExchangeVersion.Exchange2007_SP1)

service.Credentials =



NetworkCredential(" UserName", " Password" " Domain"

service.Url =



Uri( " https://DomainName/EWS/Exchange.asmx"



'绑定到登录用户的日历文件夹





Dim myCalendar As CalendarFolder = CalendarFolder.Bind(service,WellKnownFolderName.Calendar)



'查询t项他即将到来的一周 - 扩大所有重复发生





'使用CalendarView





< span style ="font-size:x-small; color:#0000ff"> Dim cv As CalendarView = CalendarView(StartTime.AddHours(-8),EndTime.AddHours(-8))

cv.PropertySet =



PropertySet(BasePropertySet.IdOnly)

cv.PropertySet.Add(AppointmentSchema.Location)


cv.PropertySet.Add(AppointmentSchema.Subject)


cv.PropertySet.Add(AppointmentSchema.Start)


cv.PropertySet.Add(AppointmentSchema.End)





'cv.PropertySet.Add(AppointmentSchema.Body)


< span style ="font-size:x-small">



< span style ="font-size:x-small; color:#008000"> 'cv.PropertySet.Add(BasePropertySet.FirstClassProperties)





Dim myAppointments As FindItemsResults( 约会)= myCalendar.FindAppointments(cv)





'写出我本周每次约会的主题





对于 每个 预约 As 约会 myAppointments



'HttpContext.Current.Response.Write(appointment.Subject +" " + appointment.Start.ToString())





Dim datastring 作为 字符串 = appointment.Subject + " ||" + appointment.Start + " ||" + appointment.End

eventList.Add(



CalendarEvent(appointment.Subject, appointment.Location,appointment.Start,appointment.End,datastring, "" ))



下一个






Catch ex As 例外



'抓住任何例外。来自

的所有错误代码



'抓住服务器上的SEARCH方法请求


< font size = 2>



'此处,也是。





投掷 ex



'HttpContext.Current.Response.Write("< span title = '" + ex.Message + "'>'连接到Exchange服务器时出现问题。稍后再试< / span>< br />")





结束 尝试





返回 < span style ="font-size:x-small"> eventList



结束 功能

解决方案

当你有一个项目实例(如约会)时,你可以调用 appointment.Load 转换为GetItem调用。要在单个调用中加载多个项目(批处理GetItem),您可以使用 ExchangeService.LoadPropertiesForItems


I run a finditem function that returns everything I need except the body. I realize I need to run a GetItem function to get the body. I can't find sample code that uses the managed API in VB. Anybody have code in VB that runs the GetItem against the managed API.

here is the first part of my code that uses find item.

 

Public Function GetEventList(ByVal StartTime As DateTime, ByVal EndTime As DateTime) As List(Of CalendarEvent)

 

Dim eventList As List(Of CalendarEvent) = New List(Of CalendarEvent)

 

Try

 

Dim service As ExchangeService = New ExchangeService(ExchangeVersion.Exchange2007_SP1)

service.Credentials =

New NetworkCredential("UserName", "Password", "Domain")

service.Url =

New Uri("https://DomainName/EWS/Exchange.asmx")

 

'Bind to the logged on user's calendar folder

 

Dim myCalendar As CalendarFolder = CalendarFolder.Bind(service, WellKnownFolderName.Calendar)

 

'Query for items for the upcoming week - Expanding all recurrences

 

'using CalendarView

 

Dim cv As CalendarView = New CalendarView(StartTime.AddHours(-8), EndTime.AddHours(-8))

cv.PropertySet =

New PropertySet(BasePropertySet.IdOnly)

cv.PropertySet.Add(AppointmentSchema.Location)

cv.PropertySet.Add(AppointmentSchema.Subject)

cv.PropertySet.Add(AppointmentSchema.Start)

cv.PropertySet.Add(AppointmentSchema.End)

 

'cv.PropertySet.Add(AppointmentSchema.Body)

 

'cv.PropertySet.Add(BasePropertySet.FirstClassProperties)

 

Dim myAppointments As FindItemsResults(Of Appointment) = myCalendar.FindAppointments(cv)

 

 

'Write out the subject of each appointment I have this week

 

For Each appointment As Appointment In myAppointments

 

'HttpContext.Current.Response.Write(appointment.Subject + " " + appointment.Start.ToString())

 

Dim datastring As String = appointment.Subject + "||" + appointment.Start + "||" + appointment.End

eventList.Add(

New CalendarEvent(appointment.Subject, appointment.Location, appointment.Start, appointment.End, datastring, ""))

 

Next

 

 

Catch ex As Exception

 

' Catch any exceptions. Any error codes from the

 

' SEARCH method requests on the server will be caught

 

' here, also.

 

Throw ex

 

'HttpContext.Current.Response.Write("<span title='" + ex.Message + "'>'There was a problem connecting to the exchange server. Try again later</span><br/>")

 

End Try

 

Return eventList

 

End Function

解决方案

When you have an instance of an item (like an appointment), you can just call appointment.Load which translates into a GetItem call. To load multiple items in a single call (batch GetItem), you can use ExchangeService.LoadPropertiesForItems.


这篇关于使用Managed API的GetItem示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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