I am trying to export data in a Microsoft Exchange 2003 public folder. However, I can not seem to retrieve the list of all non-standard/custom fields in the folder. When I try MAPIFolder.UserDefinedProperties I get an empty list. I have tried the following code, but it gives me some (not all) of the custom fields.
var document = new XDocument();
var contacts = new XElement("Contacts");
// create an instance of the Outlook Application
var outlook = new Microsoft.Office.Interop.Outlook.Application();
// get the namespace
var space = outlook.GetNamespace("MAPI");
// set folder location
var folder = space.Folders["Public Folders"]
.Folders["All Public Folders"]
.Folders["Our Company"]
.Folders["Contacts Databases"]
.Folders["Equipment Database"];
// Retrieve custom fields
// var properties = folder.UserDefinedProperties;
// Retrieve the current view
var view = XDocument.Parse(folder.CurrentView.XML);
int i = 0;
foreach (Microsoft.Office.Interop.Outlook.ContactItem item in folder.Items)
{
// create a new contact node
var contact = new XElement("Contact");
// get a reference to this item's property accessor
var access = item.PropertyAccessor;
// add the standard ContactItem fields
contact.Add(new XElement("LastName", item.LastName));
contact.Add(new XElement("FirstName", item.FirstName));
contact.Add(new XElement("Company", item.CompanyName));
contact.Add(new XElement("BusinessPhone", item.BusinessTelephoneNumber));
contact.Add(new XElement("HomePhone", item.HomeTelephoneNumber));
contact.Add(new XElement("Email", item.Email1Address));
// add the custom fields
foreach (var element in view.Descendants("column").Skip(3))
{
contact.Add(new XElement("column",
new XAttribute("heading", element.Element("heading").Value),
access.GetProperty(element.Element("prop").Value)));
}
contacts.Add(contact);
i++;
}
//var table = folder.GetTable(null, null);
//var columns = table.Columns;
//while (!table.EndOfTable)
//{
// var contact = new XElement("contact");
// var row = table.GetNextRow();
// for(int j = 1; j <= columns.Count; j++){
// string name = columns[j].Name;
// contact.Add(new XElement(name, row[name]));
// }
// contacts.Add(contact);
// i++;
//}
contacts.Add(new XAttribute("count", i));
document.Add(contacts);
Please help in whatever way possible.