Outlook, .NET, and WordML- the SECOND of a short series.

 So, Outlook programming is not always hard, but you eventually end up in the world of MAPI properties if you stay with it. That’s when it gets…uh…fun. Anyway, some things are still easy. Here is an example from my solution (see previous blog entry: http://weblogs.asp.net/johnrdurant/archive/2004/02/27/81075.aspx) that exports my Outlook tasks to a simple XML file.


This is some C# code that pulls my tasks out an dumps them to the file. Most of the code is fairly pedestrian in nature, just appending nodes etc. At the end, I check whether my XML output file exists. If it does, I delete it. If I truly had the time to be smart, I would create a simple mechanism for just creating a new file and appending some unique value so I could keep an archive of previous exports. That’s for you to add!


Some of this is a little hurried, but you will get the idea.


XmlDocument xmlDoc=new XmlDocument();

xmlDoc.AppendChild(xmlDoc.CreateProcessingInstruction("xml", "version=\"1.0\""));

xmlDoc.AppendChild(xmlDoc.CreateProcessingInstruction("mso-solutionextension","URI=\"OutlookTaskExporter\" manifestPath=\"OutlookTaskExporterSolution.xml\""));

XmlElement newRoot = xmlDoc.CreateElement("Tasks","OutlookTaskExporter");


XmlNode root = newRoot;

XmlNode newNode;


newNode.InnerText="Status Report for: John R. Durant--" + System.DateTime.Now.ToShortDateString();


XmlAttribute attNode;

Outlook.Application app=new Outlook.ApplicationClass();


Outlook.MAPIFolder tskFld=NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);


foreach(Outlook.TaskItem t in tskFld.Items)















                string[] str=categories.Split(new char [] { ',' });

                for(int i=0;i<=str.GetUpperBound(0);i++)


                     XmlNode catNode=xmlDoc.CreateElement("category","OutlookTaskExporter");

                     catNode.InnerText=str[i].TrimStart(new char [] { ' ' });



                XmlNode notesNode=xmlDoc.CreateElement("Notes","OutlookTaskExporter");





           catch (System.Exception exc)



     string filePath = "C:\\MyReports\\myTasks.xml";

     FileInfo outputFile = new FileInfo(filePath);

     if (outputFile.Exists)



One of the things to which one should pay particular attention is the area I have highlighted. This processing instruction is absolutely vital for the balance of the solution, so you should not leave it out.


One question that you will have is probably, “Why just tasks? Can I not include calendar items etc?” Of course. I focused on tasks, but you could point to other things as well.


My next entry will discuss more about the mso-solutionextension processing instruction and what it means, how it hooks up,  what it does.


Rock thought for this entry: Has anyone listened to the new P.O.D. album? Is it any good? I loved their album Satellite. Several good tunes on there with some overdrive guitar power!


Rock on!

Comments (6)

  1. Sean Terry says:

    Their latest album was a disappointment to me, and I love their Satellite album as well.

  2. Take Outs: The Digital Doggy Bag of Blog Bits for 27 February 2004

  3. Simon says:

    You might want to suggest a way of getting to the outlook interop assembly to add a reference. I was stuck for 10 mins hunting for where it could possibly be stored on the system as it wasn’t registered in the add reference dialog.

    I ended up having to copy mine from the gac using cmd and adding a reference to it, set not to copy it locally.

    Thanks for the great example!

Skip to main content