Black_Flag
asked on
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.Ol ItemType.o lAppointme ntItem)
oAppt.MeetingStatus = Outlook.OlMeetingStatus.ol Meeting
oAppt.Subject = "Subject"
oAppt.Body = "BodY"
oAppt.Location = "Location"
oAppt.Start = Convert.ToDateTime("6/17/2 008")
oAppt.End = Convert.ToDateTime("6/17/2 008")
oAppt.ReminderSet = True
oAppt.ReminderMinutesBefor eStart = 15
oAppt.BusyStatus = Outlook.OlBusyStatus.olBus y ' 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.Appl ication'); " & vbCrLf)
Response.Write("objAppoint ment = objOutlook.CreateItem(olAp pointmentI tem);" & vbCrLf)
Response.Write("objAppoint ment.Start = #6/17/2008 11:00:00 AM#;" & vbCrLf)
Response.Write("objAppoint ment.Durat ion = 60;" & vbCrLf)
Response.Write("objAppoint ment.Subje ct = 'SUBJECT';" & vbCrLf)
Response.Write("objAppoint ment.Body = 'BODY';" & vbCrLf)
Response.Write("objAppoint ment.Locat ion = 'LOCATION';" & vbCrLf)
Response.Write("objAppoint ment.Remin derMinutes BeforeStar t = 15;" & vbCrLf)
Response.Write("objAppoint ment.Remin derSet = True;" & vbCrLf)
Response.Write("objAppoint ment.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
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.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon()
Dim oAppt As Outlook.AppointmentItem = oApp.CreateItem(Outlook.Ol
oAppt.MeetingStatus = Outlook.OlMeetingStatus.ol
oAppt.Subject = "Subject"
oAppt.Body = "BodY"
oAppt.Location = "Location"
oAppt.Start = Convert.ToDateTime("6/17/2
oAppt.End = Convert.ToDateTime("6/17/2
oAppt.ReminderSet = True
oAppt.ReminderMinutesBefor
oAppt.BusyStatus = Outlook.OlBusyStatus.olBus
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""
Response.Write("Const olAppointmentItem = 1;" & vbCrLf)
Response.Write("objOutlook
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("</SCRIPT>"
I tried the above but it did not work locally or on the production server...
Any ideas? Thanks in advance..
Sam
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:
https://www.experts-exchange.com/questions/21551707/Sending-an-Outlook-VCalendar-Appointment-in-a-CDO-Message-Email.html
You may be able to email an appointment to the user:
https://www.experts-exchange.com/questions/21551707/Sending-an-Outlook-VCalendar-Appointment-in-a-CDO-Message-Email.html
ASKER
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.....
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.....
ASKER
HERE IS WHAT I AM USING FROM THE COMMENT ABOVE:
Dim sbICSFile As StringBuilder = New StringBuilder()
Dim dtNow As DateTime = DateTime.Now
sbICSFile.AppendLine("BEGI N:VCALENDA R")
sbICSFile.AppendLine("VERS ION:2.0")
sbICSFile.AppendLine("PROD ID:-//Akon aDev/Calen darAppoint ment")
sbICSFile.AppendLine("CALS CALE:GREGO RIAN")
sbICSFile.AppendLine("BEGI N:VEVENT")
' Define time zones.
' US/Eastern
sbICSFile.AppendLine("BEGI N:VTIMEZON E")
sbICSFile.AppendLine("TZID :US/Easter n")
sbICSFile.AppendLine("BEGI N:STANDARD ")
sbICSFile.AppendLine("DTST ART:200811 04T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 1SU;BYMONT H=11")
sbICSFile.AppendLine("TZOF FSETFROM:- 0400")
sbICSFile.AppendLine("TZOF FSETTO:-05 00")
sbICSFile.AppendLine("TZNA ME:EST")
sbICSFile.AppendLine("END: STANDARD")
sbICSFile.AppendLine("BEGI N:DAYLIGHT ")
sbICSFile.AppendLine("DTST ART:200803 11T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 2SU;BYMONT H=3")
sbICSFile.AppendLine("TZOF FSETFROM:- 0500")
sbICSFile.AppendLine("TZOF FSETTO:-04 00")
sbICSFile.AppendLine("TZNA ME:EDT")
sbICSFile.AppendLine("END: DAYLIGHT")
sbICSFile.AppendLine("END: VTIMEZONE" )
' US/Central
sbICSFile.AppendLine("BEGI N:VTIMEZON E")
sbICSFile.AppendLine("TZID :US/Centra l")
sbICSFile.AppendLine("BEGI N:STANDARD ")
sbICSFile.AppendLine("DTST ART:200811 04T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 1SU;BYMONT H=11")
sbICSFile.AppendLine("TZOF FSETFROM:- 0500")
sbICSFile.AppendLine("TZOF FSETTO:-06 00")
sbICSFile.AppendLine("TZNA ME:CST")
sbICSFile.AppendLine("END: STANDARD")
sbICSFile.AppendLine("BEGI N:DAYLIGHT ")
sbICSFile.AppendLine("DTST ART:200803 11T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 2SU;BYMONT H=3")
sbICSFile.AppendLine("TZOF FSETFROM:- 0600")
sbICSFile.AppendLine("TZOF FSETTO:-05 00")
sbICSFile.AppendLine("TZNA ME:CDT")
sbICSFile.AppendLine("END: DAYLIGHT")
sbICSFile.AppendLine("END: VTIMEZONE" )
' US/Mountain
sbICSFile.AppendLine("BEGI N:VTIMEZON E")
sbICSFile.AppendLine("TZID :US/Mounta in")
sbICSFile.AppendLine("BEGI N:STANDARD ")
sbICSFile.AppendLine("DTST ART:200811 04T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 1SU;BYMONT H=11")
sbICSFile.AppendLine("TZOF FSETFROM:- 0600")
sbICSFile.AppendLine("TZOF FSETTO:-07 00")
sbICSFile.AppendLine("TZNA ME:MST")
sbICSFile.AppendLine("END: STANDARD")
sbICSFile.AppendLine("BEGI N:DAYLIGHT ")
sbICSFile.AppendLine("DTST ART:200803 11T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 2SU;BYMONT H=3")
sbICSFile.AppendLine("TZOF FSETFROM:- 0700")
sbICSFile.AppendLine("TZOF FSETTO:-06 00")
sbICSFile.AppendLine("TZNA ME:MDT")
sbICSFile.AppendLine("END: DAYLIGHT")
sbICSFile.AppendLine("END: VTIMEZONE" )
' US/Pacific
sbICSFile.AppendLine("BEGI N:VTIMEZON E")
sbICSFile.AppendLine("TZID :US/Pacifi c")
sbICSFile.AppendLine("BEGI N:STANDARD ")
sbICSFile.AppendLine("DTST ART:200811 04T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 1SU;BYMONT H=11")
sbICSFile.AppendLine("TZOF FSETFROM:- 0700")
sbICSFile.AppendLine("TZOF FSETTO:-08 00")
sbICSFile.AppendLine("TZNA ME:PST")
sbICSFile.AppendLine("END: STANDARD")
sbICSFile.AppendLine("BEGI N:DAYLIGHT ")
sbICSFile.AppendLine("DTST ART:200803 11T020000" )
sbICSFile.AppendLine("RRUL E:FREQ=YEA RLY;BYDAY= 2SU;BYMONT H=3")
sbICSFile.AppendLine("TZOF FSETFROM:- 0800")
sbICSFile.AppendLine("TZOF FSETTO:-07 00")
sbICSFile.AppendLine("TZNA ME:PDT")
sbICSFile.AppendLine("END: DAYLIGHT")
sbICSFile.AppendLine("END: VTIMEZONE" )
' Define the event
sbICSFile.Append("DTSTART; TZID=" + "US/Central" + ":")
sbICSFile.Append(Now().Yea r.ToString ())
sbICSFile.Append(FormatDat eTimeValue (Now().Mon th))
sbICSFile.Append(FormatDat eTimeValue (Now().Day ) + "T")
sbICSFile.AppendLine("10:0 0 AM")
sbICSFile.Append("DTEND;TZ ID=" + "US/Central" + ":")
sbICSFile.Append(Now().Yea r.ToString ())
sbICSFile.Append(FormatDat eTimeValue (Now().Mon th))
sbICSFile.Append(FormatDat eTimeValue (Now().Day ) + "T")
sbICSFile.AppendLine("11:0 0 AM")
sbICSFile.AppendLine("SUMM ARY:SUMMAR Y")
sbICSFile.AppendLine("DESC RIPTION:EV ENT")
sbICSFile.AppendLine("UID: 1")
sbICSFile.AppendLine("SEQU ENCE:0")
sbICSFile.Append("DTSTAMP: " + dtNow.Year.ToString())
sbICSFile.Append(FormatDat eTimeValue (dtNow.Mon th))
sbICSFile.Append(FormatDat eTimeValue (dtNow.Day ) + "T")
sbICSFile.Append(FormatDat eTimeValue (dtNow.Hou r))
sbICSFile.AppendLine(Forma tDateTimeV alue(dtNow .Minute) + "00")
sbICSFile.AppendLine("END: VEVENT")
sbICSFile.AppendLine("END: VCALENDAR" )
Response.ContentType = "text/calendar"
Response.AddHeader("conten t-disposit ion", _
"attachment; filename=CalendarEvent1.ic s")
Response.Write(sbICSFile)
Response.End()
*Errors out in outlook - Cannot import vCalendar file. One or more parameter values are not valid.
Dim sbICSFile As StringBuilder = New StringBuilder()
Dim dtNow As DateTime = DateTime.Now
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("VERS
sbICSFile.AppendLine("PROD
sbICSFile.AppendLine("CALS
sbICSFile.AppendLine("BEGI
' Define time zones.
' US/Eastern
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("TZID
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("END:
' US/Central
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("TZID
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("END:
' US/Mountain
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("TZID
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("END:
' US/Pacific
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("TZID
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("BEGI
sbICSFile.AppendLine("DTST
sbICSFile.AppendLine("RRUL
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZOF
sbICSFile.AppendLine("TZNA
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("END:
' Define the event
sbICSFile.Append("DTSTART;
sbICSFile.Append(Now().Yea
sbICSFile.Append(FormatDat
sbICSFile.Append(FormatDat
sbICSFile.AppendLine("10:0
sbICSFile.Append("DTEND;TZ
sbICSFile.Append(Now().Yea
sbICSFile.Append(FormatDat
sbICSFile.Append(FormatDat
sbICSFile.AppendLine("11:0
sbICSFile.AppendLine("SUMM
sbICSFile.AppendLine("DESC
sbICSFile.AppendLine("UID:
sbICSFile.AppendLine("SEQU
sbICSFile.Append("DTSTAMP:
sbICSFile.Append(FormatDat
sbICSFile.Append(FormatDat
sbICSFile.Append(FormatDat
sbICSFile.AppendLine(Forma
sbICSFile.AppendLine("END:
sbICSFile.AppendLine("END:
Response.ContentType = "text/calendar"
Response.AddHeader("conten
"attachment; filename=CalendarEvent1.ic
Response.Write(sbICSFile)
Response.End()
*Errors out in outlook - Cannot import vCalendar file. One or more parameter values are not valid.
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.
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())
ASKER
Ok, I believe you are right about 2007 vs. 2003 as I am using 2003 here.
I changed to Response.Write(sbICSFile.T oString()) ....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.
I changed to Response.Write(sbICSFile.T
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.
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
http://www.codeproject.com/KB/vb/vcalendar.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dim fileName As String = Server.MapPath("Event.vcs" )
Dim writer As System.IO.StreamWriter = New System.IO.StreamWriter(fil eName)
writer.WriteLine("BEGIN:VC ALENDAR")
writer.WriteLine("PRODID:- //Microsof t Corporation//Outlook MIMEDIR//EN")
writer.WriteLine("VERSION: 1.0")
writer.WriteLine("BEGIN:VE VENT")
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("CATEGORI ES:Mainten ance")
'Toss the description of maintenance into the notes field.
writer.WriteLine("DESCRIPT ION;ENCODI NG=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:VEVE NT")
writer.WriteLine("END:VCAL ENDAR")
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=QUOTE D-PRINTABL E:Notes=0D =0A
SUMMARY:TEST Maintenance
PRIORITY:3
END:VEVENT
END:VCALENDAR
Dim writer As System.IO.StreamWriter = New System.IO.StreamWriter(fil
writer.WriteLine("BEGIN:VC
writer.WriteLine("PRODID:-
writer.WriteLine("VERSION:
writer.WriteLine("BEGIN:VE
Dim dueDate As DateTime
dueDate = Now()
writer.WriteLine("DTSTART:
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
writer.WriteLine("CATEGORI
'Toss the description of maintenance into the notes field.
writer.WriteLine("DESCRIPT
'For summary, let's tell them what kind of asset it is
writer.WriteLine("SUMMARY:
writer.WriteLine("PRIORITY
writer.WriteLine("END:VEVE
writer.WriteLine("END:VCAL
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=QUOTE
SUMMARY:TEST Maintenance
PRIORITY:3
END:VEVENT
END:VCALENDAR
ASKER
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!
Thanks for the help!
ASKER
*This works locally but NOT on the production server:
Response.Write("<SCRIPT LANGUAGE=""text/vbscript""
Response.Write("Const olAppointmentItem = 1;" & vbCrLf)
Response.Write("objOutlook
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("objAppoint
Response.Write("</SCRIPT>"