DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   visualbasicnet (http://www.daniweb.com/code/visualbasicnet.html)
-   -   Creating a Microsoft Office Outlook Appointment using Asp.net (http://www.daniweb.com/code/snippet787.html)

Fungus1487 visualbasicnet syntax
Nov 19th, 2007
This is a very brief overview of how to achieve an ON-THE-FLY creation of an appointment in the clients outlook calendar. This will not force the user to add it to there calendar but gives them the option to add it automated. Using the older .vcs file extension for outlook we can add an appointment easily by creating this document and letting hte user open it via the web. I have used the .vcs extension as it is compatible with older versions of outlook (mine being 2002) and not just 2007 +

  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. Dim outlookvcs As New System.Text.StringBuilder
  3. Dim subject As String
  4. Dim content As String
  5. Dim startdate As DateTime
  6. Dim enddate As DateTime
  7.  
  8. ' SET SUBJECT HEADER
  9. subject = "TESTING"
  10.  
  11. ' SET CONTENT [use '=0D' to make outlook perform a line break]
  12. content = "There is some content here"
  13.  
  14. ' SET DATES
  15. startdate = New DateTime(2007, 12, 25, 12, 0, 0)
  16. enddate = New DateTime(2007, 12, 25, 19, 30, 0)
  17.  
  18. With outlookvcs
  19. .Append("BEGIN:VCALENDAR" & vbLf)
  20. .Append("PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN" & vbLf)
  21. .Append("VERSION:1.0" & vbLf)
  22. .Append("BEGIN:VEVENT" & vbLf)
  23. .Append("DTSTART:" & str_outlookdate(startdate) & "T" & str_outlooktime(startdate) & "Z" & vbLf)
  24. .Append("DTEND:" & str_outlookdate(enddate) & "T" & str_outlooktime(enddate) & "Z" & vbLf)
  25. .Append("UID:1" & vbLf)
  26. .Append("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & content & "=0A" & vbLf)
  27. .Append("SUMMARY;ENCODING=QUOTED-PRINTABLE:" & subject & vbLf)
  28. .Append("PRIORITY:3" & vbLf)
  29. .Append("END:VEVENT" & vbLf)
  30. .Append("END:VCALENDAR" & vbLf)
  31. End With
  32.  
  33. Response.Clear()
  34. Response.ContentType = "text/calendar"
  35. Response.AddHeader("content-disposition", "attachment; filename=outlook_calendar_appointment.vcs")
  36. Response.Write(outlookvcs)
  37. Response.End()
  38. End Sub
  39.  
  40. Private Function str_outlookdate(ByVal dat_date As Date) As String
  41. str_outlookdate = Format(dat_date, "yyyyMMdd")
  42. End Function
  43.  
  44. Private Function str_outlooktime(ByVal dat_time As Date) As String
  45. str_outlooktime = Format(dat_time, "HHmmss")
  46. End Function