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 VCard

Example

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

NameDescription
VCard()

VCard()

VCard.cs
public VCard()

No documentation is available.

Properties

NameDescription
AdditionalNamesGets or sets the additional names, such as the middle name.
AddressesGets the postal addresses (ADR).
BirthdayGets or sets the birthday (BDAY), when it is a complete date.
CategoriesGets the categories (CATEGORIES).
EmailsGets the email addresses (EMAIL).
FamilyNameGets or sets the family name (the first component of N).
FormattedNameGets or sets the formatted name (FN), the name to show.
GivenNameGets or sets the given name.
NamePrefixGets or sets the honorific prefixes, such as "Dr.".
NameSuffixGets or sets the honorific suffixes, such as "Jr.".
NicknamesGets the nicknames (NICKNAME).
NoteGets or sets the note (NOTE).
OrganizationGets or sets the name of the organization (the first component of ORG).
OrganizationUnitsGets the units of the organization (the other components of ORG), such as the department.
OtherPropertiesGets the other properties, written back as they were read.
PhonesGets the telephone numbers (TEL).
PhotoGets or sets the photo (PHOTO) when it is in the card, or null.
PhotoMediaTypeGets or sets the media type of VCard.Photo, such as image/jpeg.
RoleGets or sets the role (ROLE).
TitleGets or sets the job title (TITLE).
UidGets or sets the unique identifier (UID).
UrlsGets the URLs (URL).
VersionGets or sets the version the card was read in. VCard.ToString writes any version.

AdditionalNames

VCard.cs

Gets or sets the additional names, such as the middle name.

public string? AdditionalNames { get; set; }

Property value

string?

Addresses

VCard.cs

Gets the postal addresses (ADR).

public IList<VCardAddress> Addresses { get; }

Property value

IList<VCardAddress>

Birthday

VCard.cs

Gets or sets the birthday (BDAY), when it is a complete date.

public DateOnly? Birthday { get; set; }

Property value

DateOnly?

Categories

VCard.cs

Gets the categories (CATEGORIES).

public IList<string> Categories { get; }

Property value

IList<string>

Emails

VCard.cs

Gets the email addresses (EMAIL).

public IList<VCardValue> Emails { get; }

Property value

IList<VCardValue>

FamilyName

VCard.cs

Gets or sets the family name (the first component of N).

public string? FamilyName { get; set; }

Property value

string?

FormattedName

VCard.cs

Gets or sets the formatted name (FN), the name to show.

public string? FormattedName { get; set; }

Property value

string?

GivenName

VCard.cs

Gets or sets the given name.

public string? GivenName { get; set; }

Property value

string?

NamePrefix

VCard.cs

Gets or sets the honorific prefixes, such as "Dr.".

public string? NamePrefix { get; set; }

Property value

string?

NameSuffix

VCard.cs

Gets or sets the honorific suffixes, such as "Jr.".

public string? NameSuffix { get; set; }

Property value

string?

Nicknames

VCard.cs

Gets the nicknames (NICKNAME).

public IList<string> Nicknames { get; }

Property value

IList<string>

Gets or sets the note (NOTE).

public string? Note { get; set; }

Property value

string?

Organization

VCard.cs

Gets or sets the name of the organization (the first component of ORG).

public string? Organization { get; set; }

Property value

string?

OrganizationUnits

VCard.cs

Gets the units of the organization (the other components of ORG), such as the department.

public IList<string> OrganizationUnits { get; }

Property value

IList<string>

OtherProperties

VCard.cs

Gets the other properties, written back as they were read.

public IList<ContentLine> OtherProperties { get; }

Property value

IList<ContentLine>

Phones

VCard.cs

Gets the telephone numbers (TEL).

public IList<VCardValue> Phones { get; }

Property value

IList<VCardValue>

Gets or sets the photo (PHOTO) when it is in the card, or null.

public ReadOnlyMemory<byte>? Photo { get; set; }

Property value

ReadOnlyMemory<byte>?

PhotoMediaType

VCard.cs

Gets or sets the media type of VCard.Photo, such as image/jpeg.

public string? PhotoMediaType { get; set; }

Property value

string?

Gets or sets the role (ROLE).

public string? Role { get; set; }

Property value

string?

Gets or sets the job title (TITLE).

public string? Title { get; set; }

Property value

string?

Gets or sets the unique identifier (UID).

public string? Uid { get; set; }

Property value

string?

Gets the URLs (URL).

public IList<VCardValue> Urls { get; }

Property value

IList<VCardValue>

Version

VCard.cs

Gets or sets the version the card was read in. VCard.ToString writes any version.

public VCardVersion Version { get; set; }

Property value

VCardVersion

Methods

NameDescription
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.cs

Creates 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)

Parameters

contact MapiContact
The contact.

Returns

VCard The card.

FromOab(OabRecord)

VCard.cs

Creates the card of a record of an offline address book: its names, SMTP address, telephone numbers, postal address, organization and title.

public static VCard FromOab(OabRecord record)

Parameters

record OabRecord
The record.

Returns

VCard The card.

Load overloads

Load(Stream)

VCard.cs

Reads the cards of a stream, until its end.

public static IReadOnlyList<VCard> Load(Stream stream)
Parameters
stream Stream
The stream.
Returns

IReadOnlyList<VCard> The cards.

Exceptions
EmailResourceLimitException
The content is larger than 64 MB.

Load(ReadOnlySpan<byte>)

VCard.cs

Reads 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)
Parameters
data ReadOnlySpan<byte>
The content of the file.
Returns

IReadOnlyList<VCard> The cards.

Load(string)

VCard.cs

Reads the cards of a .vcf file.

public static IReadOnlyList<VCard> Load(string path)
Parameters
path string
The path of the file.
Returns

IReadOnlyList<VCard> The cards.

Exceptions
EmailResourceLimitException
The content is larger than 64 MB.

Parse(string)

VCard.cs

Reads the cards of a text (a .vcf file can contain several).

public static IReadOnlyList<VCard> Parse(string text)

Parameters

text string
The text.

Returns

IReadOnlyList<VCard> The cards.

Save(string, IEnumerable<VCard>, VCardVersion)

VCard.cs

Writes cards in a .vcf file, in UTF-8.

public static void Save(string path, IEnumerable<VCard> cards, VCardVersion version = VCardVersion.V40)

Parameters

path string
The path of the file.
cards IEnumerable<VCard>
The cards.
version VCardVersion
The version of the format.

ToMapiContactBuilder()

VCard.cs

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.

public MapiContactBuilder ToMapiContactBuilder()

Returns

MapiContactBuilder The builder.

ToString overloads

ToString()

VCard.cs

Returns the card in the version it was read in (4.0 for a new card).

public override string ToString()
Returns

string The card.

ToString(VCardVersion)

VCard.cs

Returns the card in a version of the format.

public string ToString(VCardVersion version)
Parameters
version VCardVersion
The version.
Returns

string The card, with CRLF line breaks.