I need to read records containing name and email from a file or database and add them to an existing Oulook distribution list (from the private contacts, not from the GAL).
I just saw examples of reading from OL using LINQ to DASL which I have working for mail and appointments, but I can't figure out how to list the contents of a dist list:
private static void GetContacts()
{
Outlook.Application app = new Outlook.Application();
Outlook.Folder folder = (Outlook.Folder)app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
var distLists = from item in folder.Items.AsQueryable<MyDistList>()
where item.DLName == "My Dist List"
select item.Item;
var builder = new StringBuilder();
foreach (var list in distLists)
{
builder.AppendLine(list.DLName);
foreach (var item in list.Members)
{
// can't figure out how to iterate through the members here
// compiler says Object doesn't have GeNumerator...
}
}
Console.WriteLine(builder.ToString());
Console.ReadLine();
}
Once I can read the members I need to be able to add new ones which is even more trick. Any help would be appreciated.