如何把联系人信息添入客户端Outlook

很多系统现在都要求把联系人信息添入客户端OutLook中,有两种做法,一种是采用ACTIVEX 的做法,直接写入客户端OutLook数据库,但是这种做法受到客户端配置限制,要求客户端必须装有OutLook 软件,并且必须允许运行Activex 控件。另一种就是写成一个Vcard 文件,由客户去下载后自由保存。

 

 功能不是问题,重点是 OutLook 的数据格式

     

   保存联系人到OutLook:

//首先尝试保存联系人到客户端OutLook中,如果异常则转向到下载页面下载Vcard文件

function loadpage() {
        //debugger
            var url = location.href;
            var paraString = url.substring(url.indexOf("?") + 1, url.length).split("=");
            var dt = Web_OutLook.GetAContact(paraString[1]).value;// AJAX  方法 用于提取数据到页面上
            try {
                outLookApp = new ActiveXObject("Outlook.Application");
                outlookNS = outLookApp.GetNamespace("MAPI");
                theContact = outlookNS.GetDefaultFolder(10);
                theContactItems = theContact.Items;
                addItem = outLookApp.CreateItem(2);
                if (dt.Rows[0].name.split(' ').length >= 2) {
                    addItem.LastName = dt.Rows[0].name.split(' ')[dt.Rows[0].name.split(' ').length - 1];
                    for (var i = 0; i <= dt.Rows[0].name.split(' ').length - 2; i++) {
                        addItem.FirstName += dt.Rows[0].name.split(' ')[i];
                    }
                }
                else {
                    addItem.FirstName = dt.Rows[0].name;
               
                }
                addItem.Email1Address = dt.Rows[0].cardemail;
                addItem.Email2Address = dt.Rows[0].otherlemail;
                addItem.CompanyName = dt.Rows[0].companyname;
                addItem.Department = dt.Rows[0].department;
                addItem.JobTitle = dt.Rows[0].jobtitle;
                //
                addItem.BusinessAddressCountry = dt.Rows[0].country;
                addItem.BusinessAddressPostalCode = dt.Rows[0].postalcode;
                addItem.BusinessAddressState = dt.Rows[0].state;
                addItem.BusinessAddressStreet = dt.Rows[0].street;
                addItem.BusinessAddressCity = dt.Rows[0].city;
                //
                addItem.BusinessTelephoneNumber = dt.Rows[0].phone;
                addItem.BusinessFaxNumber = dt.Rows[0].fax;
                addItem.MobileTelephoneNumber = dt.Rows[0].mobile;
                //
                addItem.HomeFaxNumber = dt.Rows[0].p_fax;
                addItem.HomeTelephoneNumber = dt.Rows[0].p_phone;
                addItem.Home2TelephoneNumber = dt.Rows[0].p_mobile;
                //
                addItem.HomeAddressCity = dt.Rows[0].p_city;
                addItem.HomeAddressCountry = dt.Rows[0].p_country;
                addItem.HomeAddressStreet = dt.Rows[0].p_street;
                addItem.HomeAddressPostalCode = dt.Rows[0].p_postalcode;
                //
                addItem.IMAddress = dt.Rows[0].workim;
                addItem.Save();
                window.alert("saved.");

            }
            catch (Error) {
                window.open("url+" + dt.Rows[0].cardname.replace(".png", ".vcf"));
            }
        }

 

写Vcard 文件:

 #region string GetVcard(MDLCard mycard) 创建Vcard
    /// <summary>
    ///
    /// </summary>
    /// <param name="mycard"></param>
    /// <returns></returns>
    public string GetVcard(MDLCard mycard)
    {
        string[] phonestrs = mycard.Phone.Split('-');
        string phonestr = (phonestrs[0] == "" ? "" : "(" + phonestrs[0] + ")") + " " + (phonestrs[1] == "" ? "" : "(" + phonestrs[1] + ")") + " " + phonestrs[2] + " " + (phonestrs[3] == "" ? "" : "x " + phonestrs[3]);

        string[] faxstrs = mycard.Fax.Split('-');
        string faxstr = (faxstrs[0] == "" ? "" : "(" + faxstrs[0] + ")") + " " + (faxstrs[1] == "" ? "" : "(" + faxstrs[1] + ")") + " " + faxstrs[2];

        string[] mobilestrs = mycard.Mobile.Split('-');
        string mobilestr = (mobilestrs[0] == "" ? "" : "(" + mobilestrs[0] + ")") + " " + (mobilestrs[1] == "" ? "" : "(" + mobilestrs[1] + ")") + " " + mobilestrs[2];

        string[] p_phonestrs = mycard.P_phone.Split('-');
        string p_phonestr = (p_phonestrs[0] == "" ? "" : "(" + p_phonestrs[0] + ")") + " " + (p_phonestrs[1] == "" ? "" : "(" + p_phonestrs[1] + ")") + " " + p_phonestrs[2];

        string[] p_faxstrs = mycard.P_fax.Split('-');
        string p_faxstr = (p_faxstrs[0] == "" ? "" : "(" + p_faxstrs[0] + ")") + " " + (p_faxstrs[1] == "" ? "" : "(" + p_faxstrs[1] + ")") + " " + p_faxstrs[2];

        string[] p_mobilestrs = mycard.P_mobile.Split('-');
        string p_mobilestr = (p_mobilestrs[0] == "" ? "" : "(" + p_mobilestrs[0] + ")") + " " + (p_mobilestrs[1] == "" ? "" : "(" + p_mobilestrs[1] + ")") + " " + p_mobilestrs[2];

        string vcards = "";
        vcards += "BEGIN:VCARD" + "/n";
        vcards += "VERSION:2.1" + "/n";
        vcards += "N:" + mycard.Name + ";" + "" + "/n";
        vcards += "FN:" + mycard.Name + "/n";
        vcards += "NICKNAME:nickName" + "/n";
        vcards += "ORG:" + mycard.CompanyName + ";" + mycard.Department + "/n";
        vcards += "TITLE:" + mycard.JobTitle + "/n";
        vcards += "NOTE;ENCODING=QUOTED-PRINTABLE:=C6=E4=CB=FB" + "/n";
        vcards += "TEL;WORK;VOICE:" + phonestr + "/n";
        vcards += "TEL;WORK;VOICE:" + "" + "/n";
        vcards += "TEL;HOME;VOICE:" + p_phonestr + "/n";
        vcards += "TEL;HOME;VOICE:" + "" + "/n";
        vcards += "TEL;CELL;VOICE:" + mobilestr + "/n";
        vcards += "TEL;PAGER;VOICE:" + "" + "/n";
        vcards += "TEL;WORK;FAX:" + faxstr + "/n";
        vcards += "TEL;HOME;FAX:" + p_faxstr + "/n";
        vcards += "ADR;WORK:;;" + mycard.street + ";" + mycard.City + ";" + mycard.State + ";" + mycard.Postalcode + ";" + mycard.Country + "/n";
        vcards += "LABEL;WORK;ENCODING=QUOTED-PRINTABLE:=B5=A5=CE=BB=B5=D8=D6=B7" + "/n";
        vcards += "=C9=EE=DB=DA" + "/n";
        vcards += "=B9=E3=B6=AB" + "/n";
        vcards += "" + "/n";
        vcards += "=B9=FA=BC=D2" + "/n";
        vcards += "ADR;HOME;POSTAL;PARCEL:;;" + mycard.P_street + ";" + mycard.P_city + ";" + mycard.P_states + ";" + mycard.P_postalcode + ";" + mycard.P_country + "/n";
        vcards += "LABEL;HOME;ENCODING=QUOTED-PRINTABLE:=BD=D6=B5=C0=B5=D8=D6=B7" + "/n";
        vcards += "=C9=EE=DB=DA" + "/n";
        vcards += "=B9=E3=B6=AB" + "/n";
        vcards += "433330" + "/n";
        vcards += "=D6=D0=B9=FA" + "/n";
        vcards += "URL:" + "http://" + "/n";
        vcards += "URL:" + mycard.WebSite + "/n";
        vcards += "EMAIL;PREF;INTERNET:" + mycard.cardEmail + "/n";
        vcards += "X-QQ:" + "" + "/n";
        vcards += "X-ICQ:icq" + "/n";
        vcards += "X-WAB-GENDER:2" + "/n";
        vcards += "REV:" + "" + "/n";
        vcards += "END:VCARD";
        return vcards;


    }

    #endregion

 

 

 #region void FileWriter(string path, string message) 将指定信息写入指定文件
    /// <summary>
    /// 将指定信息写入指定文件
    /// </summary>
    /// <param name="path"></param>
    /// <param name="message"></param>
    public void FileWriter(string path, string message)
    {
        try
        {
            File.Delete(path);
            Stream mystream = File.Open(path, FileMode.Create, FileAccess.Write);
            StreamWriter mywriter = new StreamWriter(mystream);
            mywriter.WriteLine(message);
            mywriter.Flush();
            mystream.Close();
        }
        catch (Exception ex)
        {
            //Response.Write("<script>alert('failed')</script>");
        }
    }
    #endregion

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值