469,920 Members | 2,187 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,920 developers. It's quick & easy.

Create Outlook vcard

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
3 7240

"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
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

"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.

Similar topics

1 post views Thread by Ed | last post: by
4 posts views Thread by Nicholas Then | last post: by
1 post views Thread by Jason Karns | last post: by
1 post views Thread by MuZZy | last post: by
4 posts views Thread by R Wood | last post: by
8 posts views Thread by Dotan Cohen | last post: by
reply views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.