"scott" <sb*****@milesl umber.com> wrote in message
news:OM******** ******@TK2MSFTN GP12.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;VOIC E:' + PhoneWork + @crlf, '')
+ COALESCE ('TEL;WORK;FAX: ' + FaxWork + @crlf, '')
+ COALESCE ('TEL;HOME;VOIC E:' + [PhoneHome] + @crlf, '')
+ COALESCE ('TEL;HOME;FAX: ' + [FaxHome] + @crlf, '')
+ COALESCE ('TEL;CELL;VOIC E:' + [PhoneMobile] + @crlf, '')
+ COALESCE ('TEL;PAGER;VOI CE:' + [Pager] + @crlf, '')
+ 'ADR;WORK:;;' + COALESCE ([Address], '') + ';'
+ COALESCE ([City], '') + ';' + COALESCE ([State], '') + ';'
+ COALESCE ([Zip], '') + @crlf
+ COALESCE ('EMAIL;PREF;IN TERNET:' + [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.co m/getvcard.asp?id =123456
Hope it helps,
Mark
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '
<%
Dim ContactID, Sql, rs, ConnStr, cn, cmd
ContactID = Request("id")
Set cmd = Server.CreateOb ject("ADODB.Com mand")
Set cn = Server.CreateOb ject("ADODB.Con nection")
' Build a connection string for your environment
ConnStr = "Provider=SQLOL EDB;Server=(loc al);Database=my database"
cn.Open ConnStr
Set cmd.ActiveConne ction = cn
' Build a VBS string using the SQL above
Sql = "..."
cmd.CommandText = Sql
Dim RecsAffected, CmdParams
CmdParams = Array(CLng(Cont actID))
Set rs = cmd.Execute(Rec sAffected, CmdParams)
If (rs.State = 1) Then
Response.Conten tType = "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
%>