Create Outlook vcard

Discussion in 'ASP General' started by scott, May 17, 2005.

  1. scott

    scott Guest

    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.
    scott, May 17, 2005
    #1
    1. Advertising

  2. "scott" <> wrote in message
    news:...
    > 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:' + + @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=mydatabase"
    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

    %>
    Mark J. McGinty, May 18, 2005
    #2
    1. Advertising

  3. scott

    scott Guest

    where does this code send the results to the asp file?


    "Mark J. McGinty" <> wrote in message
    news:...
    >
    > "scott" <> wrote in message
    > news:...
    >> 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:' + + @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=mydatabase"
    > 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
    >
    > %>
    >
    >
    >
    >[/color]
    scott, May 18, 2005
    #3
  4. "scott" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >>
    >> "scott" <> wrote in message
    >> news:...
    >>> 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:' + + @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=mydatabase"
    >> 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
    >>
    >> %>
    >>
    >>
    >>
    >>[/color]
    >
    >[/color]
    Mark J. McGinty, May 18, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. localhost

    Make VCard?

    localhost, Jan 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    3,264
    localhost
    Jan 9, 2004
  2. Ike

    vCard/vCal

    Ike, Nov 12, 2003, in forum: Java
    Replies:
    3
    Views:
    5,973
    Tobias Vogele
    Nov 12, 2003
  3. Jason Karns

    XSLT stylesheet vcard RDF to VCF

    Jason Karns, Nov 10, 2005, in forum: XML
    Replies:
    1
    Views:
    1,057
    Andy Dingley
    Nov 10, 2005
  4. Ravi
    Replies:
    2
    Views:
    1,038
  5. R Wood
    Replies:
    4
    Views:
    542
    Adam Atlas
    Apr 24, 2007
Loading...

Share This Page