1

我编写了以下 VB 代码来使用 Exchange 托管 API 创建联系人。它会在收件箱的默认“联系人”文件夹中创建一个联系人。但是我需要知道如何修改它以将联系人保存到公用文件夹中。如果有人知道如何在 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
4

1 回答 1

1

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

contact.Save(folderId)

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

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

于 2013-07-13T08:04:09.530 回答