Exchange ews托管api创建公用文件夹中的项目

时间:2013-06-15 12:26:28

标签: c# vb.net exchange-server exchangewebservices

我编写了以下VB代码,以使用Exchange托管API创建联系人。它会在收件箱中的默认“contacts”文件夹中创建联系人。但是,我需要知道如何修改它以将联系人保存到公用文件夹中。 如果有人知道如何在C#中做到这一点,请随意回复,因为我可以转换回VB。

Function create_contact()
    ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
    Dim service As New ExchangeService(requestedServerVersion:=ExchangeVersion.Exchange2007_SP1)
    'Add a valid EWS service end point here or user Autodiscover

    service.Url = New Uri("https://server/ews/exchange.asmx")

    'Add a valid user credentials

    service.Credentials = New WebCredentials("username", "password", "domain")

    'To address the SSL challenge

    ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)

    Try


        Dim contact As Contact = New Contact(service)

        contact.GivenName = "Brian"
        contact.MiddleName = "David"
        contact.Surname = "Johnson"
        contact.FileAsMapping = FileAsMapping.SurnameCommaGivenName
        contact.Save()



        MsgBox("Contact created!!!")

    Catch ex As Exception

        MsgBox(ex.Message)

    End Try



End Function

1 个答案:

答案 0 :(得分:1)

您可以将文件夹ID指定为Contact类的Save方法的参数。

contact.Save(folderId)

其中folderId是您的destionation公用文件夹的ID

有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/dd635209(v=exchg.80).aspx