Hi,
Try this
HTML
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="10" valign="top">
<asp:Image ID="imgPhoto" runat="server" ImageUrl="~/Images/Mudassar.png" />
</td>
</tr>
<tr>
<td style="width: 100px">Name:
</td>
<td>
<asp:Label ID="lblName" runat="server" Text="Mudassar Khan" />
</td>
</tr>
<tr>
<td style="width: 100px">Company Name:
</td>
<td>
<asp:Label ID="lblOrganization" runat="server" Text="ASPSnippets Private Limited" />
</td>
</tr>
<tr>
<td style="width: 100px">Title (Position):
</td>
<td>
<asp:Label ID="lblTitle" runat="server" Text="Director" />
</td>
</tr>
<tr>
<td>Mobile Number:
</td>
<td>
<asp:Label ID="lblMobileNumber" runat="server" Text="9800000000" />
</td>
</tr>
<tr>
<td>Home Number:
</td>
<td>
<asp:Label ID="lblHomeNumber" runat="server" Text="6300000000" />
</td>
</tr>
<tr>
<td>Work Number:
</td>
<td>
<asp:Label ID="lblWorkNumber" runat="server" Text="7800000000" />
</td>
</tr>
<tr>
<td>Email Address:
</td>
<td>
<asp:Label ID="lblEmailAddress" runat="server" Text="mudassar.khan@aspsnippets.com" />
</td>
</tr>
<tr>
<td>Website:
</td>
<td>
<asp:Label ID="lblWebsite" runat="server" Text="www.mudassarkhan.com" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="txtCreate" runat="server" Text="Create VCF" OnClick="txtCreate_Click" />
</td>
</tr>
</table>
Namespaces
C#
using System.IO;
using System.Text;
VB.Net
Imports System.IO
Imports Text
Code
C#
protected void txtCreate_Click(object sender, EventArgs e)
{
StringBuilder fw = new StringBuilder();
fw.Append("BEGIN:VCARD\r\nVERSION:2.1");
fw.Append(Environment.NewLine);
fw.Append("N:");
fw.Append(lblName.Text.Split(' ')[0]);
fw.Append(";");
fw.Append(lblName.Text.Split(' ')[1]);
fw.Append(";");
fw.Append(Environment.NewLine);
fw.Append("FN:");
fw.Append(lblName.Text);
fw.Append(Environment.NewLine);
fw.Append("TEL;CELL:");
fw.Append(lblMobileNumber.Text);
fw.Append(Environment.NewLine);
fw.Append("TEL;HOME:");
fw.Append(lblHomeNumber.Text);
fw.Append(Environment.NewLine);
fw.Append("TEL;WORK:");
fw.Append(lblWorkNumber.Text);
fw.Append(Environment.NewLine);
fw.Append("EMAIL;WORK:");
fw.Append(lblEmailAddress.Text);
fw.Append(Environment.NewLine);
fw.Append("ORG:");
fw.Append(lblOrganization.Text);
fw.Append(Environment.NewLine);
fw.Append("TITLE:");
fw.Append(lblTitle.Text);
fw.Append(Environment.NewLine);
fw.Append("URL:");
fw.Append(lblWebsite.Text);
fw.Append(Environment.NewLine);
byte[] bytes = File.ReadAllBytes(Server.MapPath("~/Images/Mudassar.png"));
string base64 = Convert.ToBase64String(bytes, 0, bytes.Length);
fw.Append("PHOTO;ENCODING=BASE64;JPEG:");
fw.Append(base64);
fw.Append(Environment.NewLine);
fw.Append("END:VCARD");
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=Mudassar.vcf");
Response.Charset = "";
Response.ContentType = "text/vcard";
Response.Output.Write(fw.ToString());
Response.Flush();
Response.End();
}
VB.Net
Protected Sub txtCreate_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim fw As StringBuilder = New StringBuilder()
fw.Append("BEGIN:VCARD" & vbCrLf & "VERSION:2.1")
fw.Append(Environment.NewLine)
fw.Append("N:")
fw.Append(lblName.Text.Split(" "c)(0))
fw.Append(";")
fw.Append(lblName.Text.Split(" "c)(1))
fw.Append(";")
fw.Append(Environment.NewLine)
fw.Append("FN:")
fw.Append(lblName.Text)
fw.Append(Environment.NewLine)
fw.Append("TEL;CELL:")
fw.Append(lblMobileNumber.Text)
fw.Append(Environment.NewLine)
fw.Append("TEL;HOME:")
fw.Append(lblHomeNumber.Text)
fw.Append(Environment.NewLine)
fw.Append("TEL;WORK:")
fw.Append(lblWorkNumber.Text)
fw.Append(Environment.NewLine)
fw.Append("EMAIL;WORK:")
fw.Append(lblEmailAddress.Text)
fw.Append(Environment.NewLine)
fw.Append("ORG:")
fw.Append(lblOrganization.Text)
fw.Append(Environment.NewLine)
fw.Append("TITLE:")
fw.Append(lblTitle.Text)
fw.Append(Environment.NewLine)
fw.Append("URL:")
fw.Append(lblWebsite.Text)
fw.Append(Environment.NewLine)
Dim bytes As Byte() = File.ReadAllBytes(Server.MapPath("~/Images/Mudassar.png"))
Dim base64 As String = Convert.ToBase64String(bytes, 0, bytes.Length)
fw.Append("PHOTO;ENCODING=BASE64;JPEG:")
fw.Append(base64)
fw.Append(Environment.NewLine)
fw.Append("END:VCARD")
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=Mudassar.vcf")
Response.Charset = ""
Response.ContentType = "text/vcard"
Response.Output.Write(fw.ToString())
Response.Flush()
Response.End()
End Sub
Screenshot
The Form
Downloaded VCF File