VCard Class
A contact in the vCard format (.vcf), in the versions 2.1, 3.0 ([RFC 2426]) and 4.0 ([RFC 6350]). The common properties have members; the others are kept in VCard.OtherProperties and written back.
public sealed class VCardExample
var card = VCard.Load(path).Single();
Assert.Equal("Mary Ann O'Brien", card.FormattedName);
Assert.Equal("Example, Ltd.", card.Organization);
Assert.Equal("mary@example.com", card.Emails.First(email => email.HasType("pref")).Value);
Assert.Equal("Springfield", card.Addresses.Single().Locality);
// The card in another version of the format
var text = card.ToString(VCardVersion.V40);
Assert.Contains("EMAIL;PREF=1;TYPE=internet,work:mary@example.com", text, StringComparison.Ordinal);Constructors
| Name | Description |
|---|---|
| VCard() |
VCard()
VCard.cspublic VCard()No documentation is available.
Properties
| Name | Description |
|---|---|
| AdditionalNames | Gets or sets the additional names, such as the middle name. |
| Addresses | Gets the postal addresses (ADR). |
| Birthday | Gets or sets the birthday (BDAY), when it is a complete date. |
| Categories | Gets the categories (CATEGORIES). |
| Emails | Gets the email addresses (EMAIL). |
| FamilyName | Gets or sets the family name (the first component of N). |
| FormattedName | Gets or sets the formatted name (FN), the name to show. |
| GivenName | Gets or sets the given name. |
| NamePrefix | Gets or sets the honorific prefixes, such as "Dr.". |
| NameSuffix | Gets or sets the honorific suffixes, such as "Jr.". |
| Nicknames | Gets the nicknames (NICKNAME). |
| Note | Gets or sets the note (NOTE). |
| Organization | Gets or sets the name of the organization (the first component of ORG). |
| OrganizationUnits | Gets the units of the organization (the other components of ORG), such as the department. |
| OtherProperties | Gets the other properties, written back as they were read. |
| Phones | Gets the telephone numbers (TEL). |
| Photo | Gets or sets the photo (PHOTO) when it is in the card, or null. |
| PhotoMediaType | Gets or sets the media type of VCard.Photo, such as image/jpeg. |
| Role | Gets or sets the role (ROLE). |
| Title | Gets or sets the job title (TITLE). |
| Uid | Gets or sets the unique identifier (UID). |
| Urls | Gets the URLs (URL). |
| Version | Gets or sets the version the card was read in. VCard.ToString writes any version. |
AdditionalNames
VCard.csAddresses
VCard.csBirthday
VCard.csCategories
VCard.csGets the categories (CATEGORIES).
Property value
Emails
VCard.csFamilyName
VCard.csFormattedName
VCard.csGivenName
VCard.csNamePrefix
VCard.csNameSuffix
VCard.csNicknames
VCard.csNote
VCard.csOrganization
VCard.csOrganizationUnits
VCard.csGets the units of the organization (the other components of ORG), such as the department.
Property value
OtherProperties
VCard.csGets the other properties, written back as they were read.
public IList<ContentLine> OtherProperties { get; }Property value
Phones
VCard.csPhoto
VCard.csGets or sets the photo (PHOTO) when it is in the card, or null.
public ReadOnlyMemory<byte>? Photo { get; set; }Property value
PhotoMediaType
VCard.csGets or sets the media type of VCard.Photo, such as image/jpeg.
public string? PhotoMediaType { get; set; }Property value
Role
VCard.csTitle
VCard.csUid
VCard.csUrls
VCard.csVersion
VCard.csGets or sets the version the card was read in. VCard.ToString writes any version.
public VCardVersion Version { get; set; }Property value
Methods
| Name | Description |
|---|---|
| FromMapi(MapiContact) | Creates the card of a contact of Outlook: its names, email addresses, telephone numbers, postal addresses, organization, web pages, birthday, note and categories. |
| FromOab(OabRecord) | Creates the card of a record of an offline address book: its names, SMTP address, telephone numbers, postal address, organization and title. |
| Load(Stream) | Reads the cards of a stream, until its end. |
| Load(ReadOnlySpan<byte>) | Reads the cards of a file, in UTF-8 (or Latin-1 when the bytes are not UTF-8). |
| Load(string) | Reads the cards of a .vcf file. |
| Parse(string) | Reads the cards of a text (a .vcf file can contain several). |
| Save(string, IEnumerable<VCard>, VCardVersion) | Writes cards in a .vcf file, in UTF-8. |
| ToMapiContactBuilder() | Creates the builder of a contact of Outlook from the card. Outlook has two postal addresses (business and home), three email addresses, and a business, home, mobile and fax telephone number: the other values are not converted. |
| ToString() | Returns the card in the version it was read in (4.0 for a new card). |
| ToString(VCardVersion) | Returns the card in a version of the format. |
FromMapi(MapiContact)
VCard.csCreates the card of a contact of Outlook: its names, email addresses, telephone numbers, postal addresses, organization, web pages, birthday, note and categories.
public static VCard FromMapi(MapiContact contact)FromOab(OabRecord)
VCard.csLoad overloads
Load(Stream)
VCard.csReads the cards of a stream, until its end.
public static IReadOnlyList<VCard> Load(Stream stream)Parameters
streamStream- The stream.
Returns
IReadOnlyList<VCard> The cards.
Exceptions
EmailResourceLimitException- The content is larger than 64 MB.
Load(ReadOnlySpan<byte>)
VCard.csReads the cards of a file, in UTF-8 (or Latin-1 when the bytes are not UTF-8).
public static IReadOnlyList<VCard> Load(ReadOnlySpan<byte> data)Load(string)
VCard.csReads the cards of a .vcf file.
public static IReadOnlyList<VCard> Load(string path)Parameters
pathstring- The path of the file.
Returns
IReadOnlyList<VCard> The cards.
Exceptions
EmailResourceLimitException- The content is larger than 64 MB.
Parse(string)
VCard.csReads the cards of a text (a .vcf file can contain several).
public static IReadOnlyList<VCard> Parse(string text)Save(string, IEnumerable<VCard>, VCardVersion)
VCard.csWrites cards in a .vcf file, in UTF-8.
public static void Save(string path, IEnumerable<VCard> cards, VCardVersion version = VCardVersion.V40)Parameters
pathstring- The path of the file.
cardsIEnumerable<VCard>- The cards.
versionVCardVersion- The version of the format.
ToMapiContactBuilder()
VCard.csCreates the builder of a contact of Outlook from the card. Outlook has two postal addresses (business and home), three email addresses, and a business, home, mobile and fax telephone number: the other values are not converted.
public MapiContactBuilder ToMapiContactBuilder()Returns
MapiContactBuilder The builder.
ToString overloads
ToString()
VCard.csToString(VCardVersion)
VCard.csReturns the card in a version of the format.
public string ToString(VCardVersion version)