By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,224 Members | 1,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,224 IT Pros & Developers. It's quick & easy.

Create Outlook vcard

P: n/a
Anyone have a link to syntax that could create an outlook vcard file format?
all examples i find are for doing it inside outlook with .net. i'm just
looking for an ASP solution.
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"scott" <sb*****@mileslumber.com> wrote in message
news:OM**************@TK2MSFTNGP12.phx.gbl...
Anyone have a link to syntax that could create an outlook vcard file
format? all examples i find are for doing it inside outlook with .net. i'm
just looking for an ASP solution.


This SQL statement will construct a vcard from a table of contacts.
(Assumes SQL Server is the db engine. You'll need to adjust field names to
match your schema, needless to say.)

---------------------------------------------

DECLARE @crlf char(2)
SET @crlf = CHAR(13) + CHAR(10)

SELECT 'BEGIN:VCARD' + @crlf
+ COALESCE ('N:' + COALESCE (Last, '') + ';'
+ COALESCE (First, '') + ';'
+ COALESCE (Mi, '') + @crlf, '')
+ COALESCE ('FN:' + FullName + @crlf, '')
+ COALESCE ('TITLE:' + Title + @crlf, '')
+ COALESCE ('ORG:' + Company + @crlf, '')
+ COALESCE ('TEL;WORK;VOICE:' + PhoneWork + @crlf, '')
+ COALESCE ('TEL;WORK;FAX:' + FaxWork + @crlf, '')
+ COALESCE ('TEL;HOME;VOICE:' + [PhoneHome] + @crlf, '')
+ COALESCE ('TEL;HOME;FAX:' + [FaxHome] + @crlf, '')
+ COALESCE ('TEL;CELL;VOICE:' + [PhoneMobile] + @crlf, '')
+ COALESCE ('TEL;PAGER;VOICE:' + [Pager] + @crlf, '')
+ 'ADR;WORK:;;' + COALESCE ([Address], '') + ';'
+ COALESCE ([City], '') + ';' + COALESCE ([State], '') + ';'
+ COALESCE ([Zip], '') + @crlf
+ COALESCE ('EMAIL;PREF;INTERNET:' + [email] + @crlf, '')
+ 'REV:' + { fn REPLACE({ fn REPLACE(
{ fn REPLACE(CONVERT(varchar, GETDATE(), 120), '-', '')
}, ':', '') }, ' ', 'T') } + 'Z'+ @crlf
+ 'END:VCARD' + @crlf AS vcard
FROM Contact WHERE ContactID = ? -- expects 1 parameter

---------------------------------------------

This chunk of ASP below will dump a vcard to the browser, using the correct
MIME type. The identity value for the row in the source table is passed-in
to the request as a URL parameter, e.g.,

http://www.mydomain.com/getvcard.asp?id=123456
Hope it helps,
Mark
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''
<%

Dim ContactID, Sql, rs, ConnStr, cn, cmd
ContactID = Request("id")

Set cmd = Server.CreateObject("ADODB.Command")
Set cn = Server.CreateObject("ADODB.Connection")

' Build a connection string for your environment
ConnStr = "Provider=SQLOLEDB;Server=(local);Database=mydatab ase"
cn.Open ConnStr
Set cmd.ActiveConnection = cn

' Build a VBS string using the SQL above
Sql = "..."

cmd.CommandText = Sql

Dim RecsAffected, CmdParams
CmdParams = Array(CLng(ContactID))

Set rs = cmd.Execute(RecsAffected, CmdParams)

If (rs.State = 1) Then
Response.ContentType = "text/x-vcard"
Response.Write rs.GetString(2, 1, "", "")
rs.close
Else
Response.Write "contact not found"
End If

cn.close
set rs = nothing
set cmd = nothing
set cn = nothing

%>


Jul 22 '05 #2

P: n/a
where does this code send the results to the asp file?
"Mark J. McGinty" <mm******@spamfromyou.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...

"scott" <sb*****@mileslumber.com> wrote in message
news:OM**************@TK2MSFTNGP12.phx.gbl...
Anyone have a link to syntax that could create an outlook vcard file
format? all examples i find are for doing it inside outlook with .net.
i'm just looking for an ASP solution.


This SQL statement will construct a vcard from a table of contacts.
(Assumes SQL Server is the db engine. You'll need to adjust field names to
match your schema, needless to say.)

---------------------------------------------

DECLARE @crlf char(2)
SET @crlf = CHAR(13) + CHAR(10)

SELECT 'BEGIN:VCARD' + @crlf
+ COALESCE ('N:' + COALESCE (Last, '') + ';'
+ COALESCE (First, '') + ';'
+ COALESCE (Mi, '') + @crlf, '')
+ COALESCE ('FN:' + FullName + @crlf, '')
+ COALESCE ('TITLE:' + Title + @crlf, '')
+ COALESCE ('ORG:' + Company + @crlf, '')
+ COALESCE ('TEL;WORK;VOICE:' + PhoneWork + @crlf, '')
+ COALESCE ('TEL;WORK;FAX:' + FaxWork + @crlf, '')
+ COALESCE ('TEL;HOME;VOICE:' + [PhoneHome] + @crlf, '')
+ COALESCE ('TEL;HOME;FAX:' + [FaxHome] + @crlf, '')
+ COALESCE ('TEL;CELL;VOICE:' + [PhoneMobile] + @crlf, '')
+ COALESCE ('TEL;PAGER;VOICE:' + [Pager] + @crlf, '')
+ 'ADR;WORK:;;' + COALESCE ([Address], '') + ';'
+ COALESCE ([City], '') + ';' + COALESCE ([State], '') + ';'
+ COALESCE ([Zip], '') + @crlf
+ COALESCE ('EMAIL;PREF;INTERNET:' + [email] + @crlf, '')
+ 'REV:' + { fn REPLACE({ fn REPLACE(
{ fn REPLACE(CONVERT(varchar, GETDATE(), 120), '-', '')
}, ':', '') }, ' ', 'T') } + 'Z'+ @crlf
+ 'END:VCARD' + @crlf AS vcard
FROM Contact WHERE ContactID = ? -- expects 1 parameter

---------------------------------------------

This chunk of ASP below will dump a vcard to the browser, using the
correct MIME type. The identity value for the row in the source table is
passed-in to the request as a URL parameter, e.g.,

http://www.mydomain.com/getvcard.asp?id=123456
Hope it helps,
Mark
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''
<%

Dim ContactID, Sql, rs, ConnStr, cn, cmd
ContactID = Request("id")

Set cmd = Server.CreateObject("ADODB.Command")
Set cn = Server.CreateObject("ADODB.Connection")

' Build a connection string for your environment
ConnStr = "Provider=SQLOLEDB;Server=(local);Database=mydatab ase"
cn.Open ConnStr
Set cmd.ActiveConnection = cn

' Build a VBS string using the SQL above
Sql = "..."

cmd.CommandText = Sql

Dim RecsAffected, CmdParams
CmdParams = Array(CLng(ContactID))

Set rs = cmd.Execute(RecsAffected, CmdParams)

If (rs.State = 1) Then
Response.ContentType = "text/x-vcard"
Response.Write rs.GetString(2, 1, "", "")
rs.close
Else
Response.Write "contact not found"
End If

cn.close
set rs = nothing
set cmd = nothing
set cn = nothing

%>

Jul 22 '05 #3

P: n/a

"scott" <sb*****@mileslumber.com> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
where does this code send the results to the asp file?
It writes a vcard to the client browser context, which detects the MIME type
as sent, and opens it with the appropriately configured/enabled handler
application. (In the case of my workstation, that handler would be Outlook,
which opens it as a contact, but the handler could be Outlook Express, Lotus
Notes, Novell's CRM thing, and presumably many others.)

The effect is analogous to downloading Excel data, and having the browser
open it as a spreadsheet.

-Mark
"Mark J. McGinty" <mm******@spamfromyou.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...

"scott" <sb*****@mileslumber.com> wrote in message
news:OM**************@TK2MSFTNGP12.phx.gbl...
Anyone have a link to syntax that could create an outlook vcard file
format? all examples i find are for doing it inside outlook with .net.
i'm just looking for an ASP solution.


This SQL statement will construct a vcard from a table of contacts.
(Assumes SQL Server is the db engine. You'll need to adjust field names
to match your schema, needless to say.)

---------------------------------------------

DECLARE @crlf char(2)
SET @crlf = CHAR(13) + CHAR(10)

SELECT 'BEGIN:VCARD' + @crlf
+ COALESCE ('N:' + COALESCE (Last, '') + ';'
+ COALESCE (First, '') + ';'
+ COALESCE (Mi, '') + @crlf, '')
+ COALESCE ('FN:' + FullName + @crlf, '')
+ COALESCE ('TITLE:' + Title + @crlf, '')
+ COALESCE ('ORG:' + Company + @crlf, '')
+ COALESCE ('TEL;WORK;VOICE:' + PhoneWork + @crlf, '')
+ COALESCE ('TEL;WORK;FAX:' + FaxWork + @crlf, '')
+ COALESCE ('TEL;HOME;VOICE:' + [PhoneHome] + @crlf, '')
+ COALESCE ('TEL;HOME;FAX:' + [FaxHome] + @crlf, '')
+ COALESCE ('TEL;CELL;VOICE:' + [PhoneMobile] + @crlf, '')
+ COALESCE ('TEL;PAGER;VOICE:' + [Pager] + @crlf, '')
+ 'ADR;WORK:;;' + COALESCE ([Address], '') + ';'
+ COALESCE ([City], '') + ';' + COALESCE ([State], '') + ';'
+ COALESCE ([Zip], '') + @crlf
+ COALESCE ('EMAIL;PREF;INTERNET:' + [email] + @crlf, '')
+ 'REV:' + { fn REPLACE({ fn REPLACE(
{ fn REPLACE(CONVERT(varchar, GETDATE(), 120), '-', '')
}, ':', '') }, ' ', 'T') } + 'Z'+ @crlf
+ 'END:VCARD' + @crlf AS vcard
FROM Contact WHERE ContactID = ? -- expects 1 parameter

---------------------------------------------

This chunk of ASP below will dump a vcard to the browser, using the
correct MIME type. The identity value for the row in the source table is
passed-in to the request as a URL parameter, e.g.,

http://www.mydomain.com/getvcard.asp?id=123456
Hope it helps,
Mark
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''
<%

Dim ContactID, Sql, rs, ConnStr, cn, cmd
ContactID = Request("id")

Set cmd = Server.CreateObject("ADODB.Command")
Set cn = Server.CreateObject("ADODB.Connection")

' Build a connection string for your environment
ConnStr = "Provider=SQLOLEDB;Server=(local);Database=mydatab ase"
cn.Open ConnStr
Set cmd.ActiveConnection = cn

' Build a VBS string using the SQL above
Sql = "..."

cmd.CommandText = Sql

Dim RecsAffected, CmdParams
CmdParams = Array(CLng(ContactID))

Set rs = cmd.Execute(RecsAffected, CmdParams)

If (rs.State = 1) Then
Response.ContentType = "text/x-vcard"
Response.Write rs.GetString(2, 1, "", "")
rs.close
Else
Response.Write "contact not found"
End If

cn.close
set rs = nothing
set cmd = nothing
set cn = nothing

%>


Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.