Here Mudassar Ahmed Khan has explained how to read vCard (.VCF) Contact Card file and import its information using C# and VB.Net.
In this article I will illustrate how to read, import and display vCard (.VCF) Contact Card file in ASP.Net.
In this article I will explain how to read vCard (.VCF) Contact Card file and import its information using C# and VB.Net.
In this article I will illustrate how to read, import and display vCard (.VCF) Contact Card file in ASP.Net.
VCF Contact Cards
A vCard file is a standard for electronic business cards. vCards are used for storing and sharing Contact Information such as name, email, phone numbers, address, etc. in Cell Phones, Email clients, etc.
Thought Project vCard Library
I am making use of the Thought Project vCard Library for reading vCard. You can download the file from the following location.
HTML Markup
The following HTML Markup consists of an Image and some Label controls for displaying the imported information from the vCard file.
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="10" valign="top">
<asp:Image ID="imgPhoto" runat="server" />
</td>
</tr>
<tr>
<td style="width: 100px">
Name:
</td>
<td>
<asp:Label ID="lblName" runat="server" />
</td>
</tr>
<tr>
<td style="width: 100px">
Company Name:
</td>
<td>
<asp:Label ID="lblOrganization" runat="server" />
</td>
</tr>
<tr>
<td>
Mobile Number:
</td>
<td>
<asp:Label ID="lblMobileNumber" runat="server" />
</td>
</tr>
<tr>
<td>
Home Number:
</td>
<td>
<asp:Label ID="lblHomeNumber" runat="server" />
</td>
</tr>
<tr>
<td>
Work Number:
</td>
<td>
<asp:Label ID="lblWorkNumber" runat="server" />
</td>
</tr>
<tr>
<td>
Email Address:
</td>
<td>
<asp:Label ID="lblEmailAddress" runat="server" />
</td>
</tr>
<tr>
<td>
Website:
</td>
<td>
<asp:Label ID="lblWebsite" runat="server" />
</td>
</tr>
</table>
Namespaces
You will need to import the following namespaces.
C#
using Thought.vCards;
VB.Net
Imports Thought.vCards
Read, Import and Display vCard (.VCF) file information in ASP.Net
Inside the Page Load event of ASP.Net Page, the vCard file is read into a vCard object. Once the vCard object is populated, the information such as Name, Organization, Phone Numbers, Email Addresses, Websites and Photo of the contact can be read and displayed.
C#
protected void Page_Load(object sender, EventArgs e)
{
//Read the vCard file into a vCard object.
vCard card = new vCard(Server.MapPath("~/vCards/Mudassar Khan.vcf"));
//Read Name.
lblName.Text = card.FormattedName;
//Read Organization.
lblOrganization.Text = card.Organization;
//Read Title.
lblTitle.Text = card.Title;
//Read Cell Phone Number.
if (card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null)
{
lblMobileNumber.Text = card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber;
}
//Read Home Number.
if (card.Phones.GetFirstChoice(vCardPhoneTypes.Home) != null)
{
lblHomeNumber.Text = card.Phones.GetFirstChoice(vCardPhoneTypes.Home).FullNumber;
}
//Read Work Number.
if (card.Phones.GetFirstChoice(vCardPhoneTypes.Work) != null)
{
lblWorkNumber.Text = card.Phones.GetFirstChoice(vCardPhoneTypes.Work).FullNumber;
}
//Read Email Address.
if (card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet) != null)
{
lblEmailAddress.Text = card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet).Address;
}
//Read Website URL.
if (card.Websites.GetFirstChoice(vCardWebsiteTypes.Personal) != null)
{
lblWebsite.Text = card.Websites.GetFirstChoice(vCardWebsiteTypes.Personal).Url;
}
//Read Photo.
if (card.Photos.Count > 0)
{
imgPhoto.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(card.Photos[0].GetBytes());
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
'Read the vCard file into a vCard object.
Dim card As New vCard(Server.MapPath("~/vCards/Mudassar Khan.vcf"))
'Read Name.
lblName.Text = card.FormattedName
'Read Organization.
lblOrganization.Text = card.Organization
'Read Title.
lblTitle.Text = card.Title
'Read Cell Phone Number.
If card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) IsNot Nothing Then
lblMobileNumber.Text = card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber
End If
'Read Home Number.
If card.Phones.GetFirstChoice(vCardPhoneTypes.Home) IsNot Nothing Then
lblHomeNumber.Text = card.Phones.GetFirstChoice(vCardPhoneTypes.Home).FullNumber
End If
'Read Work Number.
If card.Phones.GetFirstChoice(vCardPhoneTypes.Work) IsNot Nothing Then
lblWorkNumber.Text = card.Phones.GetFirstChoice(vCardPhoneTypes.Work).FullNumber
End If
'Read Email Address.
If card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet) IsNot Nothing Then
lblEmailAddress.Text = card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet).Address
End If
'Read Website URL.
If card.Websites.GetFirstChoice(vCardWebsiteTypes.Personal) IsNot Nothing Then
lblWebsite.Text = card.Websites.GetFirstChoice(vCardWebsiteTypes.Personal).Url
End If
'Read Photo.
If card.Photos.Count > 0 Then
imgPhoto.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(card.Photos(0).GetBytes())
End If
End Sub
Screenshot
Downloads
No comments:
Post a Comment