www.pudn.com > Fetion.rar > ImportContactsFromVcard.cs


namespace Imps.Client.Pc 
{ 
    using Imps.Common; 
    using System; 
    using System.IO; 
    using System.Text; 
    using System.Windows.Forms; 
 
    internal class ImportContactsFromVcard : IImportContacts 
    { 
        private ImportContactType _type; 
 
        public string GetContactsXML(IWin32Window owner, string filePath) 
        { 
            StringBuilder builder = new StringBuilder(); 
            builder.Append(""); 
            using (StreamReader reader = new StreamReader(filePath, Encoding.Default, true)) 
            { 
                string str; 
                if (!reader.ReadLine().ToUpper().Contains("BEGIN:VCARD")) 
                { 
                    throw new NotSupportedException(); 
                } 
                string str2 = ""; 
                string str3 = ""; 
                string str4 = ""; 
                while ((str = reader.ReadLine()) != null) 
                { 
                    if (str.StartsWith("TEL;CELL;VOICE:")) 
                    { 
                        str2 = str.Replace("TEL;CELL;VOICE:", ""); 
                    } 
                    if (str.StartsWith("FN")) 
                    { 
                        string[] strArray = str.Split(new char[] { ':' }); 
                        str3 = strArray[strArray.Length - 1]; 
                    } 
                    if (str.StartsWith("NICKNAME:")) 
                    { 
                        str4 = str.Replace("NICKNAME:", ""); 
                    } 
                } 
                if (str2 != "") 
                { 
                    builder.Append(""); 
                    builder.Append(string.Format("{0}", str2)); 
                    builder.Append(string.Format("{0}", str3)); 
                    builder.Append(string.Format("{0}", str4)); 
                    builder.Append(""); 
                } 
            } 
            builder.Append(""); 
            return builder.ToString(); 
        } 
 
        public string Filter 
        { 
            get 
            { 
                return "vcf files (*.vcf)|*.vcf"; 
            } 
        } 
 
        public ImportContactType Type 
        { 
            get 
            { 
                return ImportContactType.VCard; 
            } 
        } 
    } 
}