首页 新闻 会员 周边

添加联系人出现Native method call failed.错误

0
悬赏园豆:20 [已关闭问题]

各位大侠大家好:

我是从服务器上下载xml并解析后执行到这句outlook.Contacts.Items.Add(contact);时出现这个Native method call failed.错误,我之前也曾经成功添加,但一段时间后就不行了,不知道是什么原因,请您帮我看一下,小弟在此先谢谢了!

  private static void AnalyzeLoadContactXml()//通讯录下载
        {
            byte[] review = new byte[1024 * 1024];
            string s = "";
            int index = 0;
            int errRead = 0;
            string url = "phonebook_get.php?userid=" + Int32.Parse(MeraldRegistry.UserID) + "&password=" + MeraldRegistry.PassWord + "&encoding=&";
            Cursor.Current = Cursors.WaitCursor;
            errRead = WebServices.WebServicesReadXml(url, review);
            if (errRead == 0)
            {
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(MeraldUtil.ByteArrayToString(review));
                int count = int.Parse(xml.SelectSingleNode(".//count").InnerText);
                for (int i = 1; i <= count; i++)
                {
                    OutlookSession outlook = new OutlookSession();
                    Contact contact = new Contact();
                    s = xml.SelectSingleNode(".//pl" + i).InnerText;

                    //index = s.IndexOf("|");
                    //contact.LastName = s.Substring(0, index);

                    //s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.FirstName = s.Substring(0, index);
                    //contact.FirstName = "";

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.MobileTelephoneNumber = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.RadioTelephoneNumber = s.Substring(0, index);

                    //s = s.Substring(index + 1);
                    //index = s.IndexOf("|");
                    //contact.HomeAddressState = s.Substring(0, index);

                    //s = s.Substring(index + 1);
                    //index = s.IndexOf("|");
                    //contact.HomeAddressCity = s.Substring(0, index);
                    ////contact.HomeAddressCity = "";

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.HomeAddressStreet = s.Substring(0, index);
                    //contact.HomeAddressStreet = "";

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.HomeTelephoneNumber = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.CompanyName = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.Department = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.JobTitle = s.Substring(0, index);

                    //s = s.Substring(index + 1);
                    //index = s.IndexOf("|");
                    //contact.BusinessAddressState = s.Substring(0, index);

                    //s = s.Substring(index + 1);
                    //index = s.IndexOf("|");
                    //contact.BusinessAddressCity = s.Substring(0, index);
                    ////contact.BusinessAddressCity = "";

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.BusinessAddressStreet = s.Substring(0, index);
                    //contact.BusinessAddressStreet =

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.BusinessTelephoneNumber = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.Email1Address = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.Email2Address = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    //contact.WebPage = s.Substring(0, index);
                    string y = s.Substring(0, index);


                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    int indexTime = 0;
                    string str = s.Substring(0, index);
                    indexTime = str.IndexOf("-");
                    int d1 = Convert.ToInt32(str.Substring(0, indexTime));
                    str = str.Substring(indexTime + 1);
                    indexTime = str.IndexOf("-");
                    int d2 = Convert.ToInt32(str.Substring(0, indexTime));
                    int d3 = Convert.ToInt32(str.Substring(indexTime + 1));
                    contact.Birthday = new DateTime(d1, d2, d3);


                    //y = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.BusinessFaxNumber = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    index = s.IndexOf("|");
                    contact.HomeFaxNumber = s.Substring(0, index);

                    s = s.Substring(index + 1);
                    contact.Body = s;


                    outlook.Contacts.Items.Add(contact);
                    contact.Update();
                  
                }
                Cursor.Current = Cursors.Default;          
        }

 

 

xml内容如下
<?xml version="1.0" encoding="ISO-8859-1"?><mlist><count>4</count><pl1>黄婷南宁号|+8615177049722||||||||||||1601-1-1|||</pl1><pl2>农翠兰|+8613977666249||||||||||||1601-1-1|||</pl2><pl3>小农|13755426392|13522436985|中国北京海淀区西三旗|(010) 6666666|Merad|软件|乞丐|中国广西百色旧州大街|(010) 82839651|bb@163.com|a@123.com||2009-1-18|(010) 88888888|(010) 12356|明天会更好
</pl3><pl4>枝|||||||||15078685173||||1601-1-1|||</pl4></mlist>

小农小农的主页 小农小农 | 初学一级 | 园豆:180
提问于:2009-02-05 12:21
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册