private string GetVcard() { var vcard = new VCard { Version = VCardVersion.V4, FormattedName = $"{FirstName} {LastName}", FirstName = FirstName, LastName = LastName, Classification = ClassificationType.Public, Categories = new[] { "Тренер по вольной борьбе" }, Emails = new List <Email>() { new Email() { EmailAddress = Email.ToLower() } }, Telephones = new List <Telephone>() { new Telephone() { Number = Phone, Type = TelephoneType.Cell } }, Url = WebSite, DeliveryAddress = new DeliveryAddress() { Address = Location } }; return(vcard.Serialize()); }
public void Insert(IContact contact) { var vcard = new VCard { Version = VCardVersion.V4, UniqueIdentifier = contact.Id, FormattedName = contact.FullName, FirstName = contact.FirstName, LastName = contact.LastName, Organization = contact.Company, Title = contact.JobTitle, Telephones = new List <MixERP.Net.VCards.Models.Telephone>() { new MixERP.Net.VCards.Models.Telephone() { Number = contact.MobilePhone, Type = TelephoneType.Cell, Preference = 0 } }, BirthDay = contact.Birthday, Emails = new List <MixERP.Net.VCards.Models.Email>() { new MixERP.Net.VCards.Models.Email() { EmailAddress = contact.Email } }, Addresses = new List <MixERP.Net.VCards.Models.Address>() { new MixERP.Net.VCards.Models.Address() { Street = contact.Address } }, Note = contact.Notes }; var contactPath = "\\Contacts"; var otherPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString() + contactPath; bool exists = Directory.Exists(otherPath); if (!exists) { Directory.CreateDirectory(otherPath); } string Serialized = vcard.Serialize(); string path = Path.Combine(otherPath, $"{contact.Id}.vcf"); File.WriteAllText(path, Serialized); }
public ContactAttachment(string firstName, string lastName, string phone, string email, object meta = null) : this(meta) { FirstName = firstName; LastName = lastName; Phone = phone; Email = email; var generatedVCard = new VCard { Version = VCardVersion.V4, FormattedName = $"{firstName} {lastName}", FirstName = firstName, LastName = lastName }; if (!string.IsNullOrEmpty(phone)) { generatedVCard.Telephones = new[] { new Telephone { Type = TelephoneType.Cell, Number = phone } } } ; if (!string.IsNullOrEmpty(email)) { generatedVCard.Emails = new[] { new Email { Type = EmailType.Smtp, EmailAddress = email } } } ; VCard = generatedVCard.Serialize(); }
static void Main() { var vcard = new VCard { Version = VCardVersion.V3, FirstName = "Robin", LastName = "Hood", Organization = "Sherwood Inc.", Addresses = new List <Address> { new Address { Type = AddressType.Work, Street = "The Major Oak", Locality = "Sherwood Forest", PostalCode = "NG21 9RN", Country = "United Kingdom", } }, Telephones = new List <Telephone> { new Telephone { Type = TelephoneType.Work, Number = "+441623677321" } }, Emails = new List <Email> { new Email { Type = EmailType.Smtp, EmailAddress = "*****@*****.**" } } }; var qrCode = QrCode.EncodeText(vcard.Serialize(), QrCode.Ecc.Medium); File.WriteAllText("vcard-qrcode.svg", qrCode.ToSvgString(3)); }
private void exportToolStripMenuItem_Click(object sender, EventArgs e) { Console.WriteLine($"Folder path: [{FolderPath}]"); var path = Path.Combine(FolderPath, "Vcards"); Console.WriteLine($"Vcards folder path: [{path}]"); var vcardPath = Path.Combine(path, "vcard.vcf"); Console.WriteLine($"Vcard file path [{vcardPath}]"); Console.WriteLine("Export is starting..."); try { Console.WriteLine($"Attempting to create [{path}]..."); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); Console.WriteLine($"Directory [{path}] created."); } else { Console.WriteLine($"Directory [{path}] already exists!"); } if (File.Exists(vcardPath)) { Console.WriteLine($"Deleting [{vcardPath}]..."); File.Delete(vcardPath); Console.WriteLine($"Deleted [{vcardPath}]"); } } catch (Exception ex) { Console.WriteLine($"EXCEPTION: {ex.Message}"); MessageBox.Show($"Export was not successful.\n{ex.Message}", "Error while exporting"); return; } var counter = 0; foreach (var contactsSet in Contacts.Values) { foreach (var contact in contactsSet) { var vcard = new VCard() { Version = VCardVersion.V2_1, FirstName = contact.FirstName, LastName = contact.LastName, Telephones = new List <Telephone>() { new Telephone() { Number = contact.TelephoneNumber, Type = TelephoneType.Cell } }, Emails = new List <Email>() { new Email() { EmailAddress = contact.Email, Type = EmailType.Smtp } }, Photo = new Photo(true, "JPEG", contact.ImageBase64) }; try { Console.WriteLine($"Attempting to serialize [{contact} " + $"{contact.TelephoneNumber}]..."); File.AppendAllText(vcardPath, vcard.Serialize()); Console.WriteLine($"Successfully serialized [{contact} " + $"{contact.TelephoneNumber}] to [{vcardPath}]"); counter++; } catch (Exception ex) { Console.WriteLine($"EXCEPTION: {ex.Message}"); MessageBox.Show($"Export was not successful.\n{ex.Message}", "Error while exporting"); } } } Console.WriteLine($"Exporting completed ({counter} contacts exported)"); MessageBox.Show($"{counter} contacts have been exported to [{vcardPath}]", "Exported successfully", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
static void Main(string[] args) { var html = new HtmlDocument(); html.Load("your_address_books.html"); var document = html.DocumentNode; var contacts = document.QuerySelectorAll(".pam"); foreach (var node in contacts) { var vcard = new VCard() { Version = VCardVersion.V4 }; var name = node.QuerySelector("._3-96._2pio._2lek._2lel").InnerText; vcard.FormattedName = name; var nameItems = name.Split(' '); if (nameItems.Length == 1) { vcard.FirstName = name; } else if (nameItems.Length == 2) { vcard.FirstName = nameItems[0]; vcard.LastName = nameItems[1]; } else if (nameItems.Length > 2) { vcard.FirstName = nameItems[0]; vcard.MiddleName = nameItems[1]; vcard.LastName = nameItems[2]; } var infos = node.QuerySelectorAll("._3hls"); var phones = new List <Telephone>(); var emails = new List <Email>(); foreach (var info in infos) { var text = info.InnerText.Replace("@", "@"); if (text.Contains("@")) { emails.Add(new Email() { EmailAddress = text }); } else { phones.Add(new Telephone() { Number = text }); } } vcard.Telephones = phones; vcard.Emails = emails; var serialized = vcard.Serialize(); using (StreamWriter file = File.AppendText(@"contacts-new.vcf")) { file.WriteLine(serialized); } } }
private static string GetvCard(HttpRequest req) { //ContactData gen = new ContactData(ContactData.ContactOutputType.VCard3, req.Query["firstname"], req.Query["lastname"], req.Query["nickname"] // , req.Query["phone"], req.Query["mobilephone"], req.Query["email"], req.Query["country"]); //string payload = gen.ToString(); //return payload; //var data = new ContactData(ContactData.ContactOutputType.MeCard) var phone = req.Query["phone"].ToString().Trim(); var mobilephone = req.Query["mobilephone"].ToString().Trim(); var vcard = new VCard(); vcard.Version = MixERP.Net.VCards.Types.VCardVersion.V3; if (!string.IsNullOrEmpty(req.Query["firstname"])) { vcard.FirstName = req.Query["firstname"]; } if (!string.IsNullOrEmpty(req.Query["lastname"])) { vcard.LastName = req.Query["lastname"]; } if (!string.IsNullOrEmpty(req.Query["nickname"])) { vcard.NickName = req.Query["nickname"]; } if (!string.IsNullOrEmpty(req.Query["phone"])) { vcard.Telephones = new List <Telephone>() { (new Telephone() { Number = phone, Type = MixERP.Net.VCards.Types.TelephoneType.Work }) } } ; if (!string.IsNullOrEmpty(req.Query["mobilephone"])) { vcard.Telephones = new List <Telephone>() { (new Telephone() { Number = mobilephone, Type = MixERP.Net.VCards.Types.TelephoneType.Cell }) } } ; if (!string.IsNullOrEmpty(req.Query["email"])) { vcard.Emails = new List <Email>() { (new Email() { EmailAddress = req.Query["email"], Type = MixERP.Net.VCards.Types.EmailType.Smtp }) } } ; if (!string.IsNullOrEmpty(req.Query["country"])) { vcard.Addresses = new List <Address>() { (new Address() { Country = req.Query["country"] }) } } ; if (!string.IsNullOrEmpty(req.Query["title"])) { vcard.Title = req.Query["title"]; } if (!string.IsNullOrEmpty(req.Query["role"])) { vcard.Role = req.Query["role"]; } if (!string.IsNullOrEmpty(req.Query["org"])) { vcard.Organization = req.Query["org"]; } return(vcard.Serialize()); }
private void Button_Click(object sender, RoutedEventArgs e) { if (ContactList == null || ContactList.Count < 0) { MessageBox.Show("没有数据"); return; } StringBuilder serializedStr = new StringBuilder(); foreach (var contactModel in ContactList) { var vcard = new VCard { Version = VCardVersion.V2_1, FormattedName = contactModel.Name, FirstName = "", LastName = "", //Classification = ClassificationType.Confidential, //Categories = new[] { "Friend", "Fella", "Amsterdam" } }; var Telephones = new List <Telephone>(); if (!string.IsNullOrEmpty(contactModel.Phone1)) { var telephone = new Telephone() { Number = contactModel.Phone1, Type = TelephoneType.Cell }; Telephones.Add(telephone); } if (!string.IsNullOrEmpty(contactModel.Phone2)) { var telephone = new Telephone() { Number = contactModel.Phone2, Type = TelephoneType.Home }; Telephones.Add(telephone); } if (!string.IsNullOrEmpty(contactModel.Phone3)) { var telephone = new Telephone() { Number = contactModel.Phone3, Type = TelephoneType.Work }; Telephones.Add(telephone); } vcard.Telephones = Telephones; string serialized = vcard.Serialize(); serializedStr.AppendLine(serialized); } string saveFilePath = ""; System.Windows.Forms.FolderBrowserDialog openFileDialog = new System.Windows.Forms.FolderBrowserDialog(); //选择文件夹 if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { saveFilePath = openFileDialog.SelectedPath; } if (string.IsNullOrEmpty(saveFilePath)) { MessageBox.Show("请选择要保存的文件夹"); } var fileName = System.IO.Path.GetFileNameWithoutExtension(this.txt_FilePath.Text);// 没有扩展名的文件名 string path = saveFilePath + "\\" + fileName + ".vcf"; File.WriteAllText(path, serializedStr.ToString()); MessageBox.Show("保存成功!"); }
public string Montar(List <Contato> lista) { var ret = new StringBuilder(); foreach (var c in lista.ToList()) { var vcard = new VCard { Version = VCardVersion.V4, FormattedName = c.nome, //FirstName = "John", //LastName = "Doe", //Classification = ClassificationType.Confidential, Categories = c.Categorias, Addresses = new List <Address> { new Address { Type = AddressType.Home, Street = string.Concat(c.logradouro, ", nº ", c.numero, ", ", c.bairro), Locality = c.cidade, } }, Gender = c.genero, BirthDay = c.datanascimento, Emails = new List <Email> { new Email { EmailAddress = c.email } }, Telephones = new List <Telephone> { new Telephone { Type = TelephoneType.Home, Number = c.telefonefixo }, }, Note = c.Observacao, }; if (c.celular != null) { vcard.Telephones = vcard.Telephones.Concat(new List <Telephone> { new Telephone { Type = TelephoneType.Cell, Number = c.celular }, new Telephone { Type = TelephoneType.Personal, Number = c.celular.Replace(") 9", ") ") }, }); } string serialized = vcard.Serialize(); ret.AppendLine(serialized); } return(ret.ToString()); }