using System;
using System.Net;
using System.IO;
namespace WebDavNET
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
try
{
// TODO: Replace with the URL of an object on Exchange Server
string sUri = "http://ExchServer/Exchange/Administrator/Calendar/testappt.eml";
System.Uri myUri = new System.Uri(sUri);
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);
string strXMLNSInfo = "xmlns:g=\"DAV:\" " +
" xmlns:e=\"http://schemas.microsoft.com/exchange/\"" +
" xmlns:mapi=\"http://schemas.microsoft.com/mapi/\"" +
" xmlns:x=\"xml:\" xmlns:cal=\"urn:schemas:calendar:\"" +
" xmlns:dt=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\"" +
" xmlns:mail=\"urn:schemas:httpmail:\">";
string sQuery = "<?xml version=\"1.0\"?>" +
"<g:propertyupdate " + strXMLNSInfo +
"<g:set>" +
"<g:prop>" +
"<g:contentclass>urn:content-classes:appointment</g:contentclass>" +
"<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>" +
"<mail:subject>Appointment Subject</mail:subject>" +
"<cal:location>Appointment Location</cal:location>" +
"<cal:dtstart dt:dt=\"dateTime.tz\">2001-12-27T22:00:00.000Z</cal:dtstart>" +
"<cal:dtend dt:dt=\"dateTime.tz\">2001-12-27T22:30:00.000Z</cal:dtend>" +
"<cal:instancetype dt:dt=\"int\">0</cal:instancetype>" +
"<cal:busystatus>BUSY</cal:busystatus>" +
"<cal:meetingstatus>TENTATIVE</cal:meetingstatus>" +
"<cal:alldayevent dt:dt=\"boolean\">0</cal:alldayevent>" +
"</g:prop>" +
"</g:set>" +
"</g:propertyupdate>";
// Set credentials.
// TODO: Replace with appropriate user credential
NetworkCredential myCred = new NetworkCredential(@"DomainName\UserName", "UserPassword");
CredentialCache myCredentialCache = new CredentialCache();
myCredentialCache.Add(myUri, "Basic", myCred);
HttpWRequest.Credentials = myCredentialCache;
// Set headers.
HttpWRequest.KeepAlive = false;
HttpWRequest.Headers.Set("Pragma", "no-cache");
HttpWRequest.Headers.Set("Translate", "f");
HttpWRequest.ContentType = "text/xml";
HttpWRequest.ContentLength = sQuery.Length;
//Set the request timeout to 5 minutes.
HttpWRequest.Timeout = 300000;
// set the request method
HttpWRequest.Method = "PROPPATCH";
// Store the data in a byte array.
byte[] ByteQuery = System.Text.Encoding.ASCII.GetBytes(sQuery);
HttpWRequest.ContentLength = ByteQuery.Length;
Stream QueryStream = HttpWRequest.GetRequestStream();
// Write the data to be posted to the request stream.
QueryStream.Write(ByteQuery,0,ByteQuery.Length);
QueryStream.Close();
// Send the request and get the response.
HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
// Get the Status code.
int iStatCode = (int)HttpWResponse.StatusCode;
string sStatus = iStatCode.ToString();
Console.WriteLine("Status Code: {0}", sStatus);
// Get the request headers
string sReqHeaders = HttpWRequest.Headers.ToString();
Console.WriteLine(sReqHeaders);
// Read the response stream.
Stream strm = HttpWResponse.GetResponseStream();
StreamReader sr = new StreamReader(strm);
string sText = sr.ReadToEnd();
Console.WriteLine("Response: {0}", sText);
// Close the stream.
strm.Close();
// Clean up
myCred = null;
myCredentialCache = null;
HttpWRequest = null;
HttpWResponse = null;
QueryStream = null;
strm = null;
sr = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}
}