1

Outlook と SharePoint 間の連絡先の同期を含むプロジェクトに取り組んでいます。Microsoft が提供するすぐに使用できるソリューションがありますが、カスタム列の同期などの特定の要件には対応していません。この要件のために、Outlook アドインを作成する必要がありました。このアドインは、同期の結果として作成された連絡先フォルダーの ItemAdd および ItemChange イベントを処理します。

ItemChange イベントでは、[メモ] フィールドのフラグをチェックし、変更が SharePoint または Outlook から行われたかどうかを識別し、それに応じて連絡先アイテムを更新します。

これが私の ItemChange イベントのコードです。

void Items_ItemChange(object Item)
    {

        try
        {

            ContactItem ctItem = Item as Outlook.ContactItem;






            string customFieldsAndFlag = ctItem.Body;



            Dictionary<string, string> customColumnValueMapping = new Dictionary<string, string>();

            if (!string.IsNullOrEmpty(customFieldsAndFlag))
            {
                string[] flagAndFields = customFieldsAndFlag.Split(';');
                if (flagAndFields.Length == 2)
                {
                    //SharePoint to Outlook
                    if (flagAndFields[0] == "1")
                    {


                        foreach (string customColumnAndValue in flagAndFields[1].Split('|'))
                        {
                            string[] KeyAndValue = customColumnAndValue.Split('=');

                            if (KeyAndValue.Length == 2)
                            {
                                if (ctItem.UserProperties[KeyAndValue[0]] == null)
                                {
                                    ctItem.UserProperties.Add(KeyAndValue[0], OlUserPropertyType.olText, true, OlUserPropertyType.olText);
                                    ctItem.UserProperties[KeyAndValue[0]].Value = KeyAndValue[1];
                                }
                                else
                                {
                                    ctItem.UserProperties[KeyAndValue[0]].Value = KeyAndValue[1];
                                }
                            }

                        }

                        ctItem.Body = "2;" + flagAndFields[1];


                    }
                    //Outlook to SharePoint
                    else
                    {



                        foreach (string customColumnAndValue in flagAndFields[1].Split('|'))
                        {
                            string[] KeyAndValue = customColumnAndValue.Split('=');

                            if (KeyAndValue.Length == 2)
                            {
                                if (ctItem.UserProperties[KeyAndValue[0]] != null && ctItem.UserProperties[KeyAndValue[0]].Value != null)
                                {
                                    KeyAndValue[1] = ctItem.UserProperties[KeyAndValue[0]].Value.ToString();
                                }
                                customColumnValueMapping.Add(KeyAndValue[0], KeyAndValue[1]);
                            }

                        }


                        string newBody = string.Empty;

                        foreach (KeyValuePair<string, string> kvp in customColumnValueMapping)
                        {
                            newBody += kvp.Key + "=" + kvp.Value + "|";
                        }

                        if (newBody == flagAndFields[1])
                        {
                            return;
                        }
                        else
                        {
                            ctItem.Body = "0;" + newBody;
                        }


                    }

                }



            }
            ctItem.Save();

        }
        catch(System.Exception ex)
        {
            // log the error always
            Trace.TraceError("{0}: [class]:{1} [method]:{2}\n[message]:{4}\n[Stack]:\n{5}",
                DateTime.Now, // when was the error happened
                MethodInfo.GetCurrentMethod().DeclaringType.Name, // the class name
                MethodInfo.GetCurrentMethod().Name,  // the method name
                ex.Message, // the error message
                ex.StackTrace // the stack trace information
            );
            // now display a friendly error to the user
            MessageBox.Show("There was an application error, you should save your work and restart Outlook.",
              "TraceAndLog",
              MessageBoxButtons.OK,
              MessageBoxIcon.Error);
        }
    }

問題は、連絡先アイテムの更新が Outlook から初めて正常に機能することです。連絡先は適切に更新され、アドインは正常に機能し、変更は SharePoint に正常に反映されます。しかし、Outlook を使用して連絡先を再度編集しようとすると、「アイテムは別のユーザーまたは別のウィンドウで変更されたため、変更できません。アイテムのデフォルト フォルダーにコピーを作成しますか?」というポップアップが表示されます。 ?」その後、olook アドインは機能しなくなります。

誰でもこの問題の解決策を提案できますか? この関数を使用すると、同期プロセスが機能せず、変更が SharePoint に反映されないため、ctItem.Close() を使用できません。

4

0 に答える 0