Hi all -
So was poking around a few weeks ago and couldn't find any code that'll allow me to export data to vcard...The class would require a little modification to utilize, but should get you 90% of the way there
Partial Class vCardExport
Inherits System.Web.UI.Page
Private Const nameFirst As String = "FirstName"
Private Const nameLast As String = "LastName"
Private Const nameMiddle As String = "MiddleName"
Private Const nameTitle As String = "Mr"
Private Const email As String = "firstname.lastname@domain.com"
Private Const uRL As String = "www.geekswithblogs.net/sanjayu"
Private Const telephone As String = "555 555 5555"
Private Const fax As String = "555 555 5555"
Private Const mobile As String = "555 555 5555"
Private Const company As String = "My Company"
Private Const department As String = "My Department"
Private Const mtitle As String = "My Title"
Private Const profession As String = "My Profession"
Private Const office As String = "227"
Private Const addressTitle As String = "New York"
Private Const streetName As String = "42nd Street"
Private Const city As String = "New York"
Private Const region As String = "Northeast"
Private Const postCode As String = "00000"
Private Const counTry As String = "USA"
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
eVCard.VCard(Response, nameFirst, nameLast, nameMiddle, nameTitle, email, uRL, telephone, fax, mobile, company, department, mtitle, profession, office, addressTitle, streetName, city, region, postCode, counTry)
End Sub
End Class
Public Class eVCard
Inherits System.ComponentModel.Component
Public Shared Sub VCard(ByVal response As HttpResponse _
, ByVal nameFirst As String _
, ByVal nameLast As String _
, ByVal nameMiddle As String _
, ByVal nameTitle As String _
, ByVal email As String _
, ByVal uRL As String _
, ByVal telephone As String _
, ByVal fax As String _
, ByVal mobile As String _
, ByVal company As String _
, ByVal department As String _
, ByVal title As String _
, ByVal profession As String _
, ByVal office As String _
, ByVal addressTitle As String _
, ByVal streetName As String _
, ByVal city As String _
, ByVal region As String _
, ByVal postCode As String _
, ByVal counTry As String)
response.Clear()
response.Charset = ""
response.ContentType = "text/x-vCard"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
stringWrite.WriteLine("BEGIN:VCARD")
stringWrite.WriteLine("VERSION:2.1")
stringWrite.WriteLine("N:" + nameLast + ";" + nameFirst _
+ ";" + nameMiddle + ";" + nameTitle)
stringWrite.WriteLine("FN:" + nameFirst + " " + nameMiddle _
+ " " + nameLast)
stringWrite.WriteLine("ORG:" + company + ";" + department)
stringWrite.WriteLine("URL;WORK:" + uRL)
stringWrite.WriteLine("TITLE:" + title)
stringWrite.WriteLine("ROLE:" + profession)
stringWrite.WriteLine("TEL;WORK;VOICE:" + telephone)
stringWrite.WriteLine("TEL;WORK;FAX:" + fax)
stringWrite.WriteLine("TEL;CELL;VOICE:" + mobile)
stringWrite.WriteLine("EMAIL;PREF;INTERNET:" + email)
stringWrite.WriteLine("ADR;WORK;ENCODING=QUOTED-PRINTABLE:" + ";" + _
office + ";" + addressTitle + "=0D" + streetName + ";" + _
city + ";" + region + ";" + postCode + ";" + _
counTry)
stringWrite.WriteLine("END:VCARD")
response.Write(stringWrite.ToString())
response.End()
End Sub
End Class
Print | posted on Wednesday, October 31, 2007 5:06 PM