home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / App_Code / AppointmentWebDav.vb < prev    next >
Text File  |  2011-09-24  |  11KB  |  235 lines

  1. ∩╗┐Imports Microsoft.VisualBasic
  2. Imports System.Net.Mail
  3. Imports MSXML2
  4.  
  5. Public Class AppointmentWebDav
  6.     ' This class formats and sends a meeting request via SMTP email
  7.  
  8.     Public StartDate As Date
  9.     Public StartTime As String
  10.     Public EndDate As Date
  11.     Public EndTime As String
  12.     Public Subject As String
  13.     Public Summary As String
  14.     Public Location As String
  15.     Public AttendeeName As String
  16.     Public EventID As String
  17.     Public Action As String
  18.     Public Status As String
  19.  
  20.     Public Sub New(ByVal psStartDate As DateTime, _
  21.     ByVal psEndDate As DateTime, _
  22.     ByVal psSubject As String, _
  23.     ByVal psSummary As String, _
  24.     ByVal psLocation As String, _
  25.     ByVal psAttendeeName As String, _
  26.     ByVal psEventID As String, _
  27.     ByVal psAction As String, _
  28.     ByVal psStatus As String)
  29.  
  30.         ' Copy constructor parameters to public propeties
  31.  
  32.         StartDate = psStartDate
  33.         EndDate = psEndDate
  34.         Subject = psSubject
  35.         Summary = psSummary
  36.         Location = psLocation
  37.         AttendeeName = psAttendeeName
  38.         EventID = psEventID
  39.         Action = psAction
  40.         Status = psStatus
  41.     End Sub
  42.  
  43.  
  44.     Public Sub SemdAppointment(ByRef strResult As String)
  45.  
  46.         ' Variables
  47.         Dim strExchSvrName As String
  48.         Dim strMailbox As String
  49.         Dim strCalendarUri As String
  50.         Dim strApptItem As String
  51.         Dim strDomain As String
  52.         Dim strUserName As String
  53.         Dim strPassword As String
  54.         Dim strApptRequest As String
  55.         Dim strMailInfo As String
  56.         Dim strCalInfo As String
  57.         Dim strXMLNSInfo As String
  58.         Dim strHeaderInfo As String
  59.         Dim PROPPATCHRequest As System.Net.HttpWebRequest
  60.         Dim PROPPATCHResponse As System.Net.WebResponse
  61.         Dim MyCredentialCache As System.Net.CredentialCache
  62.         Dim bytes() As Byte
  63.         Dim PROPPATCHRequestStream As System.IO.Stream
  64.  
  65.         If Action = "A" Then
  66.             Try
  67.                 ' Exchange server name
  68.                 strExchSvrName = "server6"
  69.  
  70.                 ' Mailbox folder name.
  71.                 strMailbox = AttendeeName
  72.  
  73.                 ' Appointment item.
  74.                 strApptItem = "PSS" & EventID & ".eml"
  75.  
  76.                 ' URI of the user's calendar folder.
  77.                 strCalendarUri = "http://" & strExchSvrName & "/exchange/" & strMailbox & "/Calendar/"
  78.  
  79.                 ' User name and password of appointment creator.
  80.                 strUserName = "prodservices"
  81.                 strDomain = "BUSINESS"
  82.                 strPassword = "production88"
  83.  
  84.                 ' XML namespace info for the WebDAV request.
  85.                 strXMLNSInfo = "xmlns:g=""DAV:"" " & _
  86.                    "xmlns:e=""http://schemas.microsoft.com/exchange/"" " & _
  87.                    "xmlns:mapi=""http://schemas.microsoft.com/mapi/"" " & _
  88.                    "xmlns:mapit=""http://schemas.microsoft.com/mapi/proptag/"" " & _
  89.                    "xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:"" " & _
  90.                    "xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" " & _
  91.                    "xmlns:header=""urn:schemas:mailheader:"" " & _
  92.                    "xmlns:mail=""urn:schemas:httpmail:"""
  93.  
  94.                 ' Set the appointment item properties.  The reminder time is set in seconds.
  95.                 ' To create an all-day meeting, set the dtstart/dtend range for 24 hours
  96.                 ' or more and set the alldayevent property to 1.  See the documentation
  97.                 ' on the properties in the urn:schemas:calendar: namespace for more information.
  98.                 strCalInfo = "<cal:location>" & Location & "</cal:location>" & _
  99.                    "<cal:dtstart dt:dt=""dateTime.tz"">" & StartDate.ToString("yyyy-MM-dd") & "T" & StartDate.ToUniversalTime.ToString("HH:mm:ss") & ".000Z</cal:dtstart>" & _
  100.                    "<cal:dtend dt:dt=""dateTime.tz"">" & EndDate.ToString("yyyy-MM-dd") & "T" & EndDate.ToUniversalTime.ToString("HH:mm:ss") & ".000Z</cal:dtend>" & _
  101.                    "<cal:instancetype dt:dt=""int"">0</cal:instancetype>" & _
  102.                    "<cal:busystatus>" & Status & "</cal:busystatus>" & _
  103.                    "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>" & _
  104.                    "<cal:alldayevent dt:dt=""boolean"">0</cal:alldayevent>" & _
  105.                    "<cal:responserequested dt:dt=""boolean"">1</cal:responserequested>" & _
  106.                    "<cal:reminderoffset dt:dt=""int"">900</cal:reminderoffset>"
  107.                 'strCalInfo = "<cal:location>meetappt Location</cal:location>" & _
  108.                 '   "<cal:dtstart dt:dt=""dateTime.tz"">2011-02-19T23:00:00.000Z</cal:dtstart>" & _
  109.                 '   "<cal:dtend dt:dt=""dateTime.tz"">2011-02-19T23:30:00.000Z</cal:dtend>" & _
  110.                 '   "<cal:instancetype dt:dt=""int"">0</cal:instancetype>" & _
  111.                 '   "<cal:busystatus>BUSY</cal:busystatus>" & _
  112.                 '   "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>" & _
  113.                 '   "<cal:alldayevent dt:dt=""boolean"">0</cal:alldayevent>" & _
  114.                 '   "<cal:responserequested dt:dt=""boolean"">1</cal:responserequested>" & _
  115.                 '   "<cal:reminderoffset dt:dt=""int"">900</cal:reminderoffset>"
  116.  
  117.                 ' Set the required attendee of the appointment.
  118.                 strHeaderInfo = "<header:to>" & strMailbox & "</header:to>"
  119.  
  120.                 ' Set the subject of the appointment.
  121.                 strMailInfo = "<mail:subject>" & Subject & "</mail:subject>" & _
  122.                    "<mail:htmldescription>" & Summary & "</mail:htmldescription>"
  123.  
  124.                 ' Build the XML body of the PROPPATCH request.
  125.                 strApptRequest = "<?xml version=""1.0""?>" & _
  126.                    "<g:propertyupdate " & strXMLNSInfo & ">" & _
  127.                    "<g:set><g:prop>" & _
  128.                    "<g:contentclass>urn:content-classes:appointment</g:contentclass>" & _
  129.                    "<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>" & _
  130.                    strMailInfo & _
  131.                    strCalInfo & _
  132.                    strHeaderInfo & _
  133.                    "<mapi:finvited dt:dt=""boolean"">1</mapi:finvited>" & _
  134.                    "</g:prop></g:set>" & _
  135.                    "</g:propertyupdate>"
  136.  
  137.                 ' Create a new CredentialCache object and fill it with the network
  138.                 ' credentials required to access the server.
  139.                 MyCredentialCache = New System.Net.CredentialCache
  140.                 MyCredentialCache.Add(New System.Uri(strCalendarUri), "NTLM", New System.Net.NetworkCredential(strUserName, strPassword, strDomain))
  141.  
  142.                 ' Create the HttpWebRequest object.
  143.                 PROPPATCHRequest = CType(System.Net.HttpWebRequest.Create(strCalendarUri & strApptItem), System.Net.HttpWebRequest)
  144.  
  145.                 ' Add the network credentials to the request.
  146.                 PROPPATCHRequest.Credentials = MyCredentialCache
  147.  
  148.                 ' Specify the PROPPATCH method.
  149.                 PROPPATCHRequest.Method = "PROPPATCH"
  150.  
  151.                 ' Set the content type header.
  152.                 PROPPATCHRequest.ContentType = "text/xml"
  153.  
  154.                 ' Encode the body using UTF-8.
  155.                 bytes = System.Text.Encoding.UTF8.GetBytes(strApptRequest)
  156.  
  157.                 ' Set the content header length.  This must be
  158.                 ' done before writing data to the request stream.
  159.                 PROPPATCHRequest.ContentLength = bytes.Length
  160.  
  161.                 ' Get a reference to the request stream.
  162.                 PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream()
  163.  
  164.                 ' Write the message body to the request stream.
  165.                 PROPPATCHRequestStream.Write(bytes, 0, bytes.Length)
  166.  
  167.                 ' Close the Stream object to release the connection
  168.                 ' for further use.
  169.                 PROPPATCHRequestStream.Close()
  170.  
  171.                 ' Create the appointment in the Calendar folder of the
  172.                 ' user's mailbox.
  173.                 PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(), System.Net.HttpWebResponse)
  174.  
  175.                 'Console.WriteLine("Appointment successfully created.")
  176.                 strResult = "Appointment successfully created." & "<br/><br/>" & strCalInfo
  177.  
  178.                 ' Clean up.
  179.                 PROPPATCHResponse.Close()
  180.  
  181.             Catch ex As Exception
  182.                 ' Catch any exceptions. Any error codes from the PROPPATCH
  183.                 ' or MOVE method requests on the server will be caught
  184.                 ' here, also.
  185.                 '            Console.WriteLine(ex.Message)
  186.                 '                strResult = ex.Message & "<br/><br/>" & strApptRequest
  187.                 strResult = ex.Message
  188.             End Try
  189.         Else
  190.             Try
  191.                 ' Exchange server name
  192.                 strExchSvrName = "server6"
  193.  
  194.                 ' Mailbox folder name.
  195.                 strMailbox = AttendeeName
  196.  
  197.                 ' Appointment item.
  198.                 strApptItem = "PSS" & EventID & ".eml"
  199.  
  200.                 ' URI of the user's calendar folder.
  201.                 strCalendarUri = "http://" & strExchSvrName & "/exchange/" & strMailbox & "/Calendar/" & strApptItem
  202.  
  203.                 ' User name and password of appointment creator.
  204.                 strUserName = "prodservices"
  205.                 strDomain = "BUSINESS"
  206.                 strPassword = "production88"
  207.  
  208.                 'create the HttpWebRequest object
  209.                 Dim objRequest As MSXML2.XMLHTTP40
  210.                 objRequest = CreateObject("Microsoft.xmlhttp")
  211.                 objRequest.open("DELETE", strCalendarUri, False, strUserName, strPassword)
  212.                 objRequest.send()
  213.  
  214.                 If (objRequest.status >= 200 And objRequest.status < 300) Then
  215.                     strResult = "Success!   " & "Results = " & objRequest.status & ": " & objRequest.statusText
  216.                 ElseIf objRequest.status = 401 Then
  217.                     strResult = "You do not have permission to do the job. Please check your permissions on this item."
  218.                 Else
  219.                     strResult = "Request Failed.  Results = " & objRequest.status & ": " & objRequest.statusText
  220.                 End If
  221.  
  222.             Catch ex As Exception
  223.                 ' Catch any exceptions. Any error codes from the PROPPATCH
  224.                 ' or MOVE method requests on the server will be caught
  225.                 ' here, also.
  226.                 '            Console.WriteLine(ex.Message)
  227.                 '                strResult = ex.Message & "<br/><br/>" & strApptRequest
  228.                 strResult = ex.Message
  229.             End Try
  230.  
  231.         End If
  232.     End Sub
  233.  
  234. End Class
  235.