Outlook自动化从Web应用程序创建约会

时间:2009-10-28 12:50:56

标签: asp.net automation scheduling outlook-2007 appointment

使用ActiveX技术从Web应用程序自动化Outlook是一种标准做法吗?这与Telerik的RadScheduler + telerik的Exchange提供商之类的Web调度程序相比如何从Web应用程序本身安排约会?

谢谢,
Sendhil

2 个答案:

答案 0 :(得分:2)

您需要提供有关您要完成的内容的更多详细信息,而不仅仅是在Web应用程序中声明Outlook的自动化。我说这个的原因是因为它真的取决于你想要做什么。如果你要做的只是创建一个约会,那么你不需要activex。

这是您可以研究或研究的内容。立即进入展望,创建一个约会。然后转到文件菜单并执行“另存为”并将约会保存到桌面上。您会注意到该文件存储为.ics文件。您实际上可以在记事本或单词中打开此文件并查看其内容。

例如,这里是一个在记事本中的样子:

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

所以现在考虑一下,你可以使用asp.net / asp来生成约会,因为你可以访问StreamWriter和内存流。这究竟是什么意思,这意味着您可以像这样生成一个文本文件,并猜测如果您生成这样的文本文件,那么您只需创建一个约会。这是我为日历项目编写的一个示例,我编写了一个工具来跟踪我工作的公司的假期/时间请求。管理者想要的功能之一是将员工请求添加到经理日历中的一种方法。由于经理总是在展望中,他们希望快速浏览他们的展望日历,看看谁在办公室,谁不在办公室。当然,他们可以手动创建Outlook日历项目,但过多的手工工作并不理想。

所以我使用StreamWriter和内存流来生成outlook日历项。

以下是一个例子:

<%@ 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>

答案 1 :(得分:0)

有些方法可以从asp.net应用程序自动化MS office,但这样做需要您自担风险。如果我没记错的话,你很可能需要使用模拟来使dcom正常运行,这样你就可能在Web应用程序中留下一个大的安全漏洞。

我建议使用Open Office XML,因为MS不建议也不支持在Web应用程序中自动化Office。