开发者

Outlook Automation from a web application to create appointments

Is it a standard practice to automate outlook from a web application using ActiveX technology? How does this compare with a web scheduler like telerik's RadScheduler + telerik's Exchange Provider开发者_如何学JAVA to schedule an appointment from the web application itself?

Thanks,

Sendhil


You will need to provide more details about what you are trying to accomplish rather then just stating automation of outlook within a web application. The reason I say this is because it really depends on what you are trying to do. If all you are trying to do is create an appointment then no you do not need activex.

Here is something you can research or look into. Go into outlook right now, create an appointment. Then go to the file menu and do a "Save As" and save the appointment onto your desktop. You will notice the file is stored as a .ics file. You can actually open this file in notepad or word and view the contents of it.

For example here is a sample of what it looks like in notepad:

BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN
VERSION:2.0
METHOD:PUBLISH
X-MS-OLK-FORCEINSPECTOROPEN:TRUE
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:20091028T125325Z
DESCRIPTION:test\n
DTEND:20091028T133000Z
DTSTAMP:20091028T125325Z
DTSTART:20091028T130000Z
LAST-MODIFIED:20091028T125325Z
PRIORITY:5
SEQUENCE:0
SUMMARY;LANGUAGE=en-us:test
TRANSP:OPAQUE
UID:040000008200E00074C5B7101A82E008000000005062431CAC57CA01000000000000000
    0100000003E756880D89B504BBA9FF0FDC7D16F43
X-ALT-DESC;FMTTYPE=text/html:\n\n\n\n\n\n\n\n\ntest

\n\n\n X-MICROSOFT-CDO-BUSYSTATUS:BUSY X-MICROSOFT-CDO-IMPORTANCE:1 X-MICROSOFT-DISALLOW-COUNTER:FALSE X-MS-OLK-ALLOWEXTERNCHECK:TRUE X-MS-OLK-CONFTYPE:0 BEGIN:VALARM TRIGGER:-PT15M ACTION:DISPLAY DESCRIPTION:Reminder END:VALARM END:VEVENT END:VCALENDAR

So now think about this, you can use asp.net / asp to generate an appointment because you have access to a StreamWriter and a memory stream. What exactly does this mean, it means you can generate a text file just like this and guess what if you generate a text file like this then you just created an appointment. Here is an example I wrote for a calendar item, I had written a tool to track vacation / time off requests for a company I work at. One of the features managers wanted was a way to add the employee request to the managers calendar. Due to managers always being inside of outlook they wanted to quickly glance at their outlook calendar and see who was in the office and who wasn't. Sure they could manually create the outlook calendar item but too much manual work was not ideal.

So I used a StreamWriter and a memory stream to generate an outlook calendar item.

Here is an example:

<%@ Page Language="vb" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="True" trace="False"%>
<%@ import Namespace="System.IO" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title></head>
<body>
<script runat="server"> 
Sub Page_Load(Sender As Object, E As EventArgs) 

 'PARAMETERS
    Dim beginDate as Date
    Dim endDate as Date  

    Dim VType as String = Request.QueryString("vtype")
        Dim h As Double = Request.QueryString("hours")

        If h = 8 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 4:00 PM"
        ElseIf h = 4 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 12:00 PM"
        ElseIf h = 1 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 8:00 AM"
        ElseIf h = 2 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 9:00 AM"
        ElseIf h = 3 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 10:00 AM"
        ElseIf h = 5 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 12:00 PM"
        ElseIf h = 6 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 1:00 PM"
        ElseIf h = 7 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 2:00 PM"
        ElseIf h = 9 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 5:00 PM"
        ElseIf h = 10 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 6:00 PM"
        ElseIf h = 11 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 7:00 PM"
        ElseIf h = 12 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 8:00 PM"
        ElseIf h = 13 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 9:00 PM"
        ElseIf h = 14 Then
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 10:00 PM"
        Else
            beginDate = Request.QueryString("vdate") & " 7:00 AM"
            endDate = Request.QueryString("vdate") & " 12:00 AM"
        End If

    Dim myLocation as String = Request.QueryString("location")
    Dim mySubject as String = Request.QueryString("subject")
    Dim myDescription as String = Request.QueryString("Description") 

    'INITIALIZATION
    Dim mStream As new MemoryStream()
    Dim writer As new StreamWriter(mStream)

    writer.AutoFlush = true 

    'HEADER
    writer.WriteLine("BEGIN:VCALENDAR")
    writer.WriteLine("PRODID:-//Flo Inc.//FloSoft//EN")
    writer.WriteLine("BEGIN:VEVENT") 

    'BODY
    writer.WriteLine("DTSTART:" & beginDate.ToUniversalTime.ToString("yyyyMMdd\THHmmss\Z") )
    writer.WriteLine("DTEND:" & endDate.ToUniversalTime.ToString("yyyyMMdd\THHmmss\Z") )
    writer.WriteLine("LOCATION:" & myLocation)
    writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" & myDescription)
        writer.WriteLine("SUMMARY:" & mySubject)
        writer.WriteLine("X-MICROSOFT-CDO-BUSYSTATUS:FREE")

    'FOOTER
    writer.WriteLine("PRIORITY:5")
    writer.WriteLine("END:VEVENT")
    writer.WriteLine("END:VCALENDAR") 

    'MAKE IT DOWNLOADABLE
    Response.Clear() 'clears the current output content from the buffer
    Response.AppendHeader("Content-Disposition", "attachment; filename=Add2Calendar.vcs")
    Response.AppendHeader("Content-Length", mStream.Length.ToString())
    Response.ContentType = "application/download"
    Response.BinaryWrite(mStream.ToArray())
    Response.End() 
    End Sub
</script>
</body>
</html>


There are ways that you can automate MS office from an asp.net application but such you do so at your own risk. If I remember correctly, you will more than likely need to use impersonation in order for dcom to function correctly and in doing so you will possibly leave a large security hole in your web application.

I would suggest using Open Office XML as MS does not recommend nor support automating Office from within a web application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜