private void ShowFolderInTree(TreeNode parentNode, IMAPIFolder folder) { MapiFolderNode folderNode = new MapiFolderNode(folder); parentNode.Nodes.Add(folderNode); //Enumerate the child folders IMAPITable childFoldersTable; Error hr = folder.GetHierarchyTable(0, out childFoldersTable); if (hr != Error.Success) { throw new MapiException(hr); } using (childFoldersTable) { Value[,] rows; //Retrieve only one column: the entry ID childFoldersTable.SetColumns(new Tags[] {Tags.PR_ENTRYID}, IMAPITable.FLAGS.Default); //Query rows one at a time for (; childFoldersTable.QueryRows(1, 0, out rows) == Error.Success && rows.Length > 0; ) { //Get the child folder having this row ID IUnknown unk; MAPI.TYPE objType; IMAPIFolder subFolder; hr = folder.OpenEntry(ENTRYID.Create(rows[0,0]), Guid.Empty, IMAPIContainer.FLAGS.BestAccess, out objType, out unk); if (hr != Error.Success) { throw new MapiException(hr); } subFolder = (IMAPIFolder)unk; unk.Dispose(); using (subFolder) { ShowFolderInTree(folderNode, subFolder); } } } }
public void AddFolder(IMAPIFolder folder) { //Add the messages in this folder to the maildir Error hr; IMAPITable contentsTable; folder.GetContentsTable(0, out contentsTable); using(contentsTable) { MAPI33.MapiTypes.Value[,] rows; contentsTable.SetColumns(new Tags[] { Tags.PR_ENTRYID }, IMAPITable.FLAGS.Default); for( ;contentsTable.QueryRows(1, 0, out rows) == Error.Success && rows.Length > 0; ) { //Get the message object for this entry id IUnknown unk; MAPI.TYPE objType; IMessage msg; hr = folder.OpenEntry(ENTRYID.Create(rows[0,0]), Guid.Empty, IMAPIContainer.FLAGS.BestAccess, out objType, out unk); if (hr != Error.Success) { throw new MapiException(hr); } msg = (IMessage)unk; unk.Dispose(); using (msg) { AddMessage(msg); } } } }