home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tlcTest2.aspx.vb < prev    next >
Text File  |  2011-02-21  |  7KB  |  150 lines

  1. ∩╗┐Imports AspNetMaker7_tfpssnet
  2.  
  3. Partial Class tlcTest2
  4.     Inherits System.Web.UI.Page
  5.  
  6.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7.         ' Variables
  8.         Dim strExchSvrName As String
  9.         Dim strMailbox As String
  10.         Dim strCalendarUri As String
  11.         Dim strApptItem As String
  12.         Dim strDomain As String
  13.         Dim strUserName As String
  14.         Dim strPassword As String
  15.         Dim strApptRequest As String
  16.         Dim strMailInfo As String
  17.         Dim strCalInfo As String
  18.         Dim strXMLNSInfo As String
  19.         Dim strHeaderInfo As String
  20.         Dim PROPPATCHRequest As System.Net.HttpWebRequest
  21.         Dim PROPPATCHResponse As System.Net.WebResponse
  22.         Dim MyCredentialCache As System.Net.CredentialCache
  23.         Dim bytes() As Byte
  24.         Dim PROPPATCHRequestStream As System.IO.Stream
  25.  
  26.         Try
  27.             ' Exchange server name
  28.             strExchSvrName = "server6"
  29.  
  30.             ' Mailbox folder name.
  31.             strMailbox = "tonyclayton"
  32.  
  33.             ' Appointment item.
  34.             strApptItem = "testappointment.eml"
  35.  
  36.             ' URI of the user's calendar folder.
  37.             strCalendarUri = "http://" & strExchSvrName & "/exchange/" & _
  38.             strMailbox & "/Calendar/"
  39.  
  40.             ' User name and password of appointment creator.
  41.             strUserName = "prodservices"
  42.             strDomain = "BUSINESS"
  43.             strPassword = "production88"
  44.  
  45.             ' XML namespace info for the WebDAV request.
  46.             strXMLNSInfo = "xmlns:g=""DAV:"" " & _
  47.                "xmlns:e=""http://schemas.microsoft.com/exchange/"" " & _
  48.                "xmlns:mapi=""http://schemas.microsoft.com/mapi/"" " & _
  49.                "xmlns:mapit=""http://schemas.microsoft.com/mapi/proptag/"" " & _
  50.                "xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:"" " & _
  51.                "xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" " & _
  52.                "xmlns:header=""urn:schemas:mailheader:"" " & _
  53.                "xmlns:mail=""urn:schemas:httpmail:"""
  54.  
  55.             ' Set the appointment item properties.  The reminder time is set in seconds.
  56.             ' To create an all-day meeting, set the dtstart/dtend range for 24 hours
  57.             ' or more and set the alldayevent property to 1.  See the documentation
  58.             ' on the properties in the urn:schemas:calendar: namespace for more information.
  59.             strCalInfo = "<cal:location>meetappt Location</cal:location>" & _
  60.                "<cal:dtstart dt:dt=""dateTime.tz"">2011-02-19T14:00:00.000Z</cal:dtstart>" & _
  61.                "<cal:dtend dt:dt=""dateTime.tz"">2011-02-19T15:00:00.000Z</cal:dtend>" & _
  62.                "<cal:instancetype dt:dt=""int"">0</cal:instancetype>" & _
  63.                "<cal:busystatus>BUSY</cal:busystatus>" & _
  64.                "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>" & _
  65.                "<cal:alldayevent dt:dt=""boolean"">0</cal:alldayevent>" & _
  66.                "<cal:responserequested dt:dt=""boolean"">1</cal:responserequested>" & _
  67.                "<cal:reminderoffset dt:dt=""int"">900</cal:reminderoffset>"
  68.  
  69.             ' Set the required attendee of the appointment.
  70.             strHeaderInfo = "<header:to>" & strMailbox & "</header:to>"
  71.  
  72.             ' Set the subject of the appointment.
  73.             strMailInfo = "<mail:subject>Test Appointment Subject</mail:subject>" & _
  74.                "<mail:htmldescription>Let's meet here</mail:htmldescription>"
  75.  
  76.             ' Build the XML body of the PROPPATCH request.
  77.             strApptRequest = "<?xml version=""1.0""?>" & _
  78.                "<g:propertyupdate " & strXMLNSInfo & ">" & _
  79.                "<g:set><g:prop>" & _
  80.                "<g:contentclass>urn:content-classes:appointment</g:contentclass>" & _
  81.                "<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>" & _
  82.                strMailInfo & _
  83.                strCalInfo & _
  84.                strHeaderInfo & _
  85.                "<mapi:finvited dt:dt=""boolean"">1</mapi:finvited>" & _
  86.                "</g:prop></g:set>" & _
  87.                "</g:propertyupdate>"
  88.  
  89.             ' Create a new CredentialCache object and fill it with the network
  90.             ' credentials required to access the server.
  91.             MyCredentialCache = New System.Net.CredentialCache
  92.             MyCredentialCache.Add(New System.Uri(strCalendarUri), _
  93.                                   "NTLM", _
  94.                                   New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _
  95.                                   )
  96.  
  97.             ' Create the HttpWebRequest object.
  98.             PROPPATCHRequest = CType(System.Net.HttpWebRequest.Create(strCalendarUri & strApptItem),  _
  99.                                      System.Net.HttpWebRequest)
  100.  
  101.             ' Add the network credentials to the request.
  102.             PROPPATCHRequest.Credentials = MyCredentialCache
  103.  
  104.             ' Specify the PROPPATCH method.
  105.             PROPPATCHRequest.Method = "PROPPATCH"
  106.  
  107.             ' Set the content type header.
  108.             PROPPATCHRequest.ContentType = "text/xml"
  109.  
  110.             ' Encode the body using UTF-8.
  111.             bytes = System.Text.Encoding.UTF8.GetBytes(strApptRequest)
  112.  
  113.             ' Set the content header length.  This must be
  114.             ' done before writing data to the request stream.
  115.             PROPPATCHRequest.ContentLength = bytes.Length
  116.  
  117.             ' Get a reference to the request stream.
  118.             PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream()
  119.  
  120.             ' Write the message body to the request stream.
  121.             PROPPATCHRequestStream.Write(bytes, 0, bytes.Length)
  122.  
  123.             ' Close the Stream object to release the connection
  124.             ' for further use.
  125.             PROPPATCHRequestStream.Close()
  126.  
  127.             ' Create the appointment in the Calendar folder of the
  128.             ' user's mailbox.
  129.             PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(), System.Net.HttpWebResponse)
  130.  
  131.             '            Console.WriteLine("Appointment successfully created.")
  132.             Label1.Text = "Appointment successfully created.<br />"
  133.             Label1.Text = Label1.Text & strApptRequest
  134.  
  135.             ' Clean up.
  136.             PROPPATCHResponse.Close()
  137.  
  138.         Catch ex As Exception
  139.             ' Catch any exceptions. Any error codes from the PROPPATCH
  140.             ' or MOVE method requests on the server will be caught
  141.             ' here, also.
  142.             '            Console.WriteLine(ex.Message)
  143.             Label1.Text = ex.Message
  144.         End Try
  145.  
  146.  
  147.     End Sub
  148.  
  149. End Class
  150.