Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 895
  • Last Modified:

Creating Outlook Event - Client Side

I am attempting to create an outlook event client side after the user signs up in my volunteer application I am creating.  After they select their available start/end time to work the event I want to send the event to their calendar in outlook 2003.

When I run this locally on my computer from my code behind in .Net, it works:
Dim oApp As Outlook.Application = New Outlook.Application
Dim missing As Object = System.Reflection.Missing.Value
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon()
Dim oAppt As Outlook.AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
 oAppt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting
oAppt.Subject = "Subject"
oAppt.Body = "BodY"
oAppt.Location = "Location"
oAppt.Start = Convert.ToDateTime("6/17/2008")
oAppt.End = Convert.ToDateTime("6/17/2008")
oAppt.ReminderSet = True
oAppt.ReminderMinutesBeforeStart = 15
oAppt.BusyStatus = Outlook.OlBusyStatus.olBusy  '  olBusy
oAppt.IsOnlineMeeting = False
oAppt.Save()
oNS.Logoff()
oNS = Nothing
oAppt = Nothing
oApp = Nothing

* But when I run the code on our production server, the calendare event is never created, no errors, nothing....

So I believe I need to do this with a client side script in my code behind:
            Response.Write("<SCRIPT LANGUAGE=""text/vbscript"">" & vbCrLf)
            Response.Write("Const olAppointmentItem = 1;" & vbCrLf)
            Response.Write("objOutlook = CreateObject('Outlook.Application');" & vbCrLf)
            Response.Write("objAppointment = objOutlook.CreateItem(olAppointmentItem);" & vbCrLf)
            Response.Write("objAppointment.Start = #6/17/2008 11:00:00 AM#;" & vbCrLf)
            Response.Write("objAppointment.Duration = 60;" & vbCrLf)
            Response.Write("objAppointment.Subject = 'SUBJECT';" & vbCrLf)
            Response.Write("objAppointment.Body = 'BODY';" & vbCrLf)
            Response.Write("objAppointment.Location = 'LOCATION';" & vbCrLf)
            Response.Write("objAppointment.ReminderMinutesBeforeStart = 15;" & vbCrLf)
            Response.Write("objAppointment.ReminderSet = True;" & vbCrLf)
            Response.Write("objAppointment.Save();" & vbCrLf)
            Response.Write("</SCRIPT>")

I tried the above but it did not work locally or on the production server...

Any ideas? Thanks in advance..

Sam
0
Black_Flag
Asked:
Black_Flag
  • 6
  • 4
1 Solution
 
Black_FlagAuthor Commented:
CORRECTION:
*This works locally but NOT on the production server:

            Response.Write("<SCRIPT LANGUAGE=""text/vbscript"">" & vbCrLf)
            Response.Write("Const olAppointmentItem = 1;" & vbCrLf)
            Response.Write("objOutlook = CreateObject('Outlook.Application');" & vbCrLf)
            Response.Write("objAppointment = objOutlook.CreateItem(olAppointmentItem);" & vbCrLf)
            Response.Write("objAppointment.Start = #6/17/2008 11:00:00 AM#;" & vbCrLf)
            Response.Write("objAppointment.Duration = 60;" & vbCrLf)
            Response.Write("objAppointment.Subject = 'SUBJECT';" & vbCrLf)
            Response.Write("objAppointment.Body = 'BODY';" & vbCrLf)
            Response.Write("objAppointment.Location = 'LOCATION';" & vbCrLf)
            Response.Write("objAppointment.ReminderMinutesBeforeStart = 15;" & vbCrLf)
            Response.Write("objAppointment.ReminderSet = True;" & vbCrLf)
            Response.Write("objAppointment.Save();" & vbCrLf)
            Response.Write("</SCRIPT>")
0
 
molkuCommented:
Your code will try to interact with Outlook on the web server, not the client. It may be possible with client side vb script, but I'm doubtful and it would only work in IE.
You may be able to email an appointment to the user:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_21551707.html
0
 
Black_FlagAuthor Commented:
Would this work?

http://msdn.microsoft.com/en-us/library/bb655909.aspx

I added the code, changed my time zones to use the year 2008, and I am getting an error, saying that there is an error in the .ics file that was sent.....
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Black_FlagAuthor Commented:
HERE IS WHAT I AM USING FROM THE COMMENT ABOVE:

            Dim sbICSFile As StringBuilder = New StringBuilder()
            Dim dtNow As DateTime = DateTime.Now

            sbICSFile.AppendLine("BEGIN:VCALENDAR")
            sbICSFile.AppendLine("VERSION:2.0")
            sbICSFile.AppendLine("PRODID:-//AkonaDev/CalendarAppointment")
            sbICSFile.AppendLine("CALSCALE:GREGORIAN")
            sbICSFile.AppendLine("BEGIN:VEVENT")
            ' Define time zones.
            ' US/Eastern
            sbICSFile.AppendLine("BEGIN:VTIMEZONE")
            sbICSFile.AppendLine("TZID:US/Eastern")
            sbICSFile.AppendLine("BEGIN:STANDARD")
            sbICSFile.AppendLine("DTSTART:20081104T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
            sbICSFile.AppendLine("TZOFFSETFROM:-0400")
            sbICSFile.AppendLine("TZOFFSETTO:-0500")
            sbICSFile.AppendLine("TZNAME:EST")
            sbICSFile.AppendLine("END:STANDARD")
            sbICSFile.AppendLine("BEGIN:DAYLIGHT")
            sbICSFile.AppendLine("DTSTART:20080311T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
            sbICSFile.AppendLine("TZOFFSETFROM:-0500")
            sbICSFile.AppendLine("TZOFFSETTO:-0400")
            sbICSFile.AppendLine("TZNAME:EDT")
            sbICSFile.AppendLine("END:DAYLIGHT")
            sbICSFile.AppendLine("END:VTIMEZONE")

            ' US/Central
            sbICSFile.AppendLine("BEGIN:VTIMEZONE")
            sbICSFile.AppendLine("TZID:US/Central")
            sbICSFile.AppendLine("BEGIN:STANDARD")
            sbICSFile.AppendLine("DTSTART:20081104T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
            sbICSFile.AppendLine("TZOFFSETFROM:-0500")
            sbICSFile.AppendLine("TZOFFSETTO:-0600")
            sbICSFile.AppendLine("TZNAME:CST")
            sbICSFile.AppendLine("END:STANDARD")
            sbICSFile.AppendLine("BEGIN:DAYLIGHT")
            sbICSFile.AppendLine("DTSTART:20080311T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
            sbICSFile.AppendLine("TZOFFSETFROM:-0600")
            sbICSFile.AppendLine("TZOFFSETTO:-0500")
            sbICSFile.AppendLine("TZNAME:CDT")
            sbICSFile.AppendLine("END:DAYLIGHT")

            sbICSFile.AppendLine("END:VTIMEZONE")

            ' US/Mountain
            sbICSFile.AppendLine("BEGIN:VTIMEZONE")
            sbICSFile.AppendLine("TZID:US/Mountain")
            sbICSFile.AppendLine("BEGIN:STANDARD")
            sbICSFile.AppendLine("DTSTART:20081104T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
            sbICSFile.AppendLine("TZOFFSETFROM:-0600")
            sbICSFile.AppendLine("TZOFFSETTO:-0700")
            sbICSFile.AppendLine("TZNAME:MST")
            sbICSFile.AppendLine("END:STANDARD")
            sbICSFile.AppendLine("BEGIN:DAYLIGHT")
            sbICSFile.AppendLine("DTSTART:20080311T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
            sbICSFile.AppendLine("TZOFFSETFROM:-0700")
            sbICSFile.AppendLine("TZOFFSETTO:-0600")
            sbICSFile.AppendLine("TZNAME:MDT")
            sbICSFile.AppendLine("END:DAYLIGHT")
            sbICSFile.AppendLine("END:VTIMEZONE")

            ' US/Pacific
            sbICSFile.AppendLine("BEGIN:VTIMEZONE")
            sbICSFile.AppendLine("TZID:US/Pacific")
            sbICSFile.AppendLine("BEGIN:STANDARD")
            sbICSFile.AppendLine("DTSTART:20081104T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11")
            sbICSFile.AppendLine("TZOFFSETFROM:-0700")
            sbICSFile.AppendLine("TZOFFSETTO:-0800")
            sbICSFile.AppendLine("TZNAME:PST")
            sbICSFile.AppendLine("END:STANDARD")
            sbICSFile.AppendLine("BEGIN:DAYLIGHT")
            sbICSFile.AppendLine("DTSTART:20080311T020000")
            sbICSFile.AppendLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3")
            sbICSFile.AppendLine("TZOFFSETFROM:-0800")
            sbICSFile.AppendLine("TZOFFSETTO:-0700")
            sbICSFile.AppendLine("TZNAME:PDT")
            sbICSFile.AppendLine("END:DAYLIGHT")
            sbICSFile.AppendLine("END:VTIMEZONE")

            ' Define the event
            sbICSFile.Append("DTSTART;TZID=" + "US/Central" + ":")
            sbICSFile.Append(Now().Year.ToString())
            sbICSFile.Append(FormatDateTimeValue(Now().Month))
            sbICSFile.Append(FormatDateTimeValue(Now().Day) + "T")
            sbICSFile.AppendLine("10:00 AM")

            sbICSFile.Append("DTEND;TZID=" + "US/Central" + ":")
            sbICSFile.Append(Now().Year.ToString())
            sbICSFile.Append(FormatDateTimeValue(Now().Month))
            sbICSFile.Append(FormatDateTimeValue(Now().Day) + "T")
            sbICSFile.AppendLine("11:00 AM")

            sbICSFile.AppendLine("SUMMARY:SUMMARY")
            sbICSFile.AppendLine("DESCRIPTION:EVENT")
            sbICSFile.AppendLine("UID:1")
            sbICSFile.AppendLine("SEQUENCE:0")

            sbICSFile.Append("DTSTAMP:" + dtNow.Year.ToString())
            sbICSFile.Append(FormatDateTimeValue(dtNow.Month))
            sbICSFile.Append(FormatDateTimeValue(dtNow.Day) + "T")
            sbICSFile.Append(FormatDateTimeValue(dtNow.Hour))
            sbICSFile.AppendLine(FormatDateTimeValue(dtNow.Minute) + "00")

            sbICSFile.AppendLine("END:VEVENT")
            sbICSFile.AppendLine("END:VCALENDAR")

            Response.ContentType = "text/calendar"
            Response.AddHeader("content-disposition", _
                "attachment; filename=CalendarEvent1.ics")
            Response.Write(sbICSFile)
            Response.End()


*Errors out in outlook - Cannot import vCalendar file.  One or more parameter values are not valid.
0
 
molkuCommented:
I had no idea you could do this. The code in the link you posted screams for a more userfriendly component (probably is one already....).
Giving it a quick once over, I see two things that could be the problem.
First (And I doubt this is your issue, but...) the article refers to Office 2007 and you say you are using 2003.
Second, the code is writing the StringBuilder to the response. I think this is an error it should be writing the string value of the StringBuilder.
Response.Write(sbICSFile.ToString())

Open in new window

0
 
Black_FlagAuthor Commented:
Ok, I believe you are right about 2007 vs. 2003 as I am using 2003 here.

I changed to Response.Write(sbICSFile.ToString())....still got the error.

Ok, let me go back to trying to email the event.  When I first tried this, I got the same error.  So, let me try this and post back.
0
 
molkuCommented:
Good 'ol Code Project. You may want to look at this to help build your vcalendar file.
http://www.codeproject.com/KB/vb/vcalendar.aspx
0
 
molkuCommented:
Another tip.... Open an appointment in Outlook, choose File - save as - .ics file. Open the file in a text editor and examine the format, comparing it to what your code is generating to find the parameter error.
0
 
Black_FlagAuthor Commented:
           Dim fileName As String = Server.MapPath("Event.vcs")
            Dim writer As System.IO.StreamWriter = New System.IO.StreamWriter(fileName)
            writer.WriteLine("BEGIN:VCALENDAR")
            writer.WriteLine("PRODID:-//Microsoft Corporation//Outlook MIMEDIR//EN")
            writer.WriteLine("VERSION:1.0")
            writer.WriteLine("BEGIN:VEVENT")
            Dim dueDate As DateTime
            dueDate = Now()
            writer.WriteLine("DTSTART:" + dueDate.Year.ToString() + dueDate.Month.ToString() + dueDate.Day.ToString() + "T170000Z")
            writer.WriteLine("DTEND:" + dueDate.Year.ToString() + dueDate.Month.ToString() + dueDate.Day.ToString() + "T170000Z")
            'Lets set the appointment location to the actual location of the asset.
            writer.WriteLine("LOCATION:TEST")
            writer.WriteLine("CATEGORIES:Maintenance")
            'Toss the description of maintenance into the notes field.
            writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + "Notes" + "=0D=0A")
            'For summary, let's tell them what kind of asset it is
            writer.WriteLine("SUMMARY:" + "TEST" + " Maintenance")
            writer.WriteLine("PRIORITY:3")
            writer.WriteLine("END:VEVENT")
            writer.WriteLine("END:VCALENDAR")
            writer.Close()


Here is what it looks like in notepad:
BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook MIMEDIR//EN
VERSION:1.0
BEGIN:VEVENT
DTSTART:2008617T170000Z
DTEND:2008617T170000Z
LOCATION:TEST
CATEGORIES:Maintenance
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:Notes=0D=0A
SUMMARY:TEST Maintenance
PRIORITY:3
END:VEVENT
END:VCALENDAR
0
 
Black_FlagAuthor Commented:
I saved a test appointment like you suggested from oulook and then opened it up in notepad and compared and found some items that I was leaving out.  It works now!

Thanks for the help!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now