Solved

Creating Outlook Event - Client Side

Posted on 2008-06-17
10
877 Views
Last Modified: 2008-06-18
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
Comment
Question by:Black_Flag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 1

Author Comment

by:Black_Flag
ID: 21804276
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
 
LVL 4

Expert Comment

by:molku
ID: 21804871
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
 
LVL 1

Author Comment

by:Black_Flag
ID: 21805433
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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 1

Author Comment

by:Black_Flag
ID: 21805462
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
 
LVL 4

Expert Comment

by:molku
ID: 21805552
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
 
LVL 1

Author Comment

by:Black_Flag
ID: 21805599
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
 
LVL 4

Expert Comment

by:molku
ID: 21805679
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
 
LVL 4

Accepted Solution

by:
molku earned 500 total points
ID: 21805756
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
 
LVL 1

Author Comment

by:Black_Flag
ID: 21805847
           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
 
LVL 1

Author Comment

by:Black_Flag
ID: 21815558
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question