Lorenzo Soncini
{
// Variables.
string strExchSvrName = "";
string strMailbox = "";
string strTaskUri = "";
string strTaskItem = "";
string strDomain = "";
string strUserName = "";
string strPassword = "";
string strApptRequest = "";
string strMailInfo = "";
string strTaskInfo = "";
string strXMLNSInfo = "";
string strHeaderInfo = "";
System.Net.HttpWebRequest PROPPATCHRequest = null;
System.Net.WebResponse PROPPATCHResponse = null;
System.Net.CredentialCache MyCredentialCache = null;
byte[] bytes = null;
System.IO.Stream PROPPATCHRequestStream = null;
try
{
strExchSvrName = "servername";
strMailbox = "mailbox";
strTaskItem = "testtask.eml";
strTaskUri = "http://" + strExchSvrName + "/exchange/"
+ strMailbox + "/tasks/";
// User name and password of appointment creator.
strUserName = "user";
strDomain = "domain";
strPassword = "password";
// XML namespace info for the WebDAV request.
strXMLNSInfo = "xmlns:g=\"DAV:\" "
+ "xmlns:e=\"http://schemas.microsoft.com/exchange/\" "
+ "xmlns:mapi=\"http://schemas.microsoft.com/mapi/\" "
+ "xmlns:mapit=\"http://schemas.microsoft.com/mapi/proptag/\" "
+ "xmlns:dt=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" "
+
"xmlns:h=\"http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/\"
"
+
"xmlns:i=\"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/\"
"
+ "xmlns:header=\"urn:schemas:mailheader:\" "
+ "xmlns:mail=\"urn:schemas:httpmail:\"";
strTaskInfo = "<h:0x00008104
dt:dt=\"dateTime.tz\">2005-09-29T00:00:00Z</h:0x00008104>"
+ "<h:0x00008105
dt:dt=\"dateTime.tz\">2005-09-29T00:00:00Z</h:0x00008105>"
+ "<h:0x0000811C dt:dt=\"boolean\">0</h:0x0000811C>"
+ "<h:0x00008101 dt:dt=\"int\">0</h:0x00008101>"
+ "<h:0x00008102 dt:dt=\"float\">0</h:0x00008102>"
+ "<i:0x00008503 dt:dt=\"boolean\">1</i:0x00008503>";
strHeaderInfo = "<header:to>" + strMailbox + "</header:to>";
strMailInfo = "<mail:subject>Test Task Subject</mail:subject>"
+ "<mail:htmldescription>Test Description</mail:htmldescription>";
// Build the XML body of the PROPPATCH request.
strApptRequest = "<?xml version=\"1.0\"?>"
+ "<g:propertyupdate " + strXMLNSInfo + ">"
+ "<g:set><g:prop>"
+ "<g:contentclass>urn:content-classes:task</g:contentclass>"
+ "<e:outlookmessageclass>IPM.Task</e:outlookmessageclass>"
+ strMailInfo
+ strTaskInfo
+ strHeaderInfo
+ "</g:prop></g:set>"
+ "</g:propertyupdate>";
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add( new System.Uri(strTaskUri),
"NTLM",
new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
);
PROPPATCHRequest =
(System.Net.HttpWebRequest)HttpWebRequest.Create(strTaskUri + strTaskItem);
PROPPATCHRequest.Credentials = MyCredentialCache;
PROPPATCHRequest.Method = "PROPPATCH";
bytes = Encoding.UTF8.GetBytes((string)strApptRequest);
PROPPATCHRequest.ContentLength = bytes.Length;
PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream();
PROPPATCHRequestStream.Write(bytes, 0, bytes.Length);
PROPPATCHRequestStream.Close();
PROPPATCHRequest.ContentType = "text/xml";
PROPPATCHResponse =
(System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
PROPPATCHResponse.Close();
Console.WriteLine("Task successfully created.");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Cheers
Glen
"Lorenzo Soncini" <lorenzo...@technoservice.com> wrote in message
news:Or0af01w...@TK2MSFTNGP09.phx.gbl...
{
Outlook.ApplicationClass oApp = new Outlook.ApplicationClass();
Outlook.NameSpace oNS = oApp.GetNamespace( "MAPI" );
Outlook.MAPIFolder oFolder = oNS.GetDefaultFolder(
Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders );
Outlook.MAPIFolder oPublicTaskFolder = oFolder.Items.Item(
"MyPublicTaskFolder" );
Outlook._Items oItems = oPublicTaskFolder.Items;
Outlook._TaskItem oTask = (Outlook._TaskItem) oItems.Add(
"IPM.Task" );
oTask.Subject = "My Subject";
oTask.Body = "Notes and other text go here";
oTask.StartDAte = DateTime.Now;
oTask.DueDate = DateTime.Now.AddDays(7); //Due a week from now
oTask.Save();
// et voila!
// now clean up and you're set to go.
oTask = null;
oApp = null;
GC.WaitForPendingFinalizers();
GC.Collect();
}
You'd need to add Outlook to your references.
Alex
"Glen Scales [MVP]" <gsc...@outlookexchange.com> wrote in message
news:eRfaF4Ix...@TK2MSFTNGP11.phx.gbl...
Cheers
Glen
"Alex" <Alex...@newsgroups.nospam> wrote in message
news:eaSIPPQx...@TK2MSFTNGP09.phx.gbl...
Alex
"Glen Scales [MVP]" <gsc...@outlookexchange.com> wrote in message
news:upwS3UUx...@TK2MSFTNGP11.phx.gbl...