Free Trial
Web API version
Licensing
Request A Quote
HAVE QUESTIONS OR NEED HELP? SUBMIT THE SUPPORT REQUEST FORM or write email to SUPPORT@BYTESCOUT.COM
QR Code with vCard | C#
Program.cs:
C#
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using Bytescout.BarCode; using CreateBarCode; namespace Sample { class Program { static void Main(string[] args) { // Create new barcode Barcode barcode = new Barcode(); // Set symbology barcode.Symbology = SymbologyType.QRCode; // Inputs var oQrcodeVCard = new QrCodeVCardTemplate { FirstName = "Forest", LastName = "Gump", Company = "Bubba Gump Shrimp Co.", Job = "Shrimp Man", Phone = "+1-111-555-1212", Fax = "+1-404-555-1212", Email = "forrestgump@example.com", Street = "100 Waters Edge", City = "Baytown", State = "LA", Country = "USA", ZipCode = "30314" }; // Set value barcode.Value = oQrcodeVCard.ToString(); // Save barcode to image barcode.SaveImage("result.png"); // Show image in default image viewer Process.Start("result.png"); } } }
QrCodeVCardTemplate.cs:
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CreateBarCode { class QrCodeVCardTemplate { #region Constructors public QrCodeVCardTemplate() { } public QrCodeVCardTemplate(string FirstName, string LastName, string Phone, string Fax, string Email, string Company, string Job, string Street, string City, string State, string ZipCode, string Country) { this.FirstName = FirstName; this.LastName = LastName; this.Phone = Phone; this.Fax = Fax; this.Email = Email; this.Company = Company; this.Job = Job; this.State = State; this.City = City; this.Street = Street; this.Country = Country; this.ZipCode = ZipCode; } #endregion #region Properties public string FirstName { get; set; } public string LastName { get; set; } public string Phone { get; set; } public string Fax { get; set; } public string Email { get; set; } public string Company { get; set; } public string Job { get; set; } public string Street { get; set; } public string City { get; set; } public string State { get; set; } public string Country { get; set; } public string ZipCode { get; set; } #endregion #region Overloaded Methods public override string ToString() { if (string.IsNullOrEmpty(FirstName) && string.IsNullOrEmpty(LastName)) return base.ToString(); return $@"BEGIN:VCARD VERSION:2.1 N:{LastName};{FirstName};; FN:{FirstName} {LastName} ORG:{Company} TITLE:{Job} TEL;WORK;VOICE:{Phone} TEL;FAX;VOICE:{Fax} ADR;WORK;PREF:;;{Street};{City};{State};{ZipCode};{Country} LABEL;WORK;PREF;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8 EMAIL:{Email} END:VCARD "; } #endregion } }