I have a collection of objects (oItems) that I want to use to populate a
dataset. Basically I want to take several elements from oItems (such as
SenderName, Subject and Body) and use them to populate separate columns
of a dataset, and then use the dataset to populate a gridview.
Can anybody help me out with this?
//Create Outlook application
Outlook.Applica tion oApp = new Outlook.Applica tion();
//Get MAPI namespace
Outlook.NameSpa ce oNS = oApp.GetNamespa ce("mapi");
oNS.Logon("name ", "password", false, true);
//Get Messages collection of Inbox
Outlook.MAPIFol der oInbox =
oNS.GetDefaultF older(Outlook.O lDefaultFolders .olFolderInbox) ;
Outlook.Items oItems = oInbox.Items;
int intTotalNumberO fItemsInInbox = oItems.Count;
//Get unread e-mail messages
oItems = oItems.Restrict ("[Unread] = true");
int intTotalUnread = oItems.Count;
//Loop through each unread message
Outlook.MailIte m oMsg;
int i;
for (i = 1; i < oItems.Count; i++)
{
oMsg = (Outlook.MailIt em)oItems.Item( i);
txtSenderName.T ext = oMsg.SenderName .ToString();
txtSubject.Text = oMsg.Subject.To String();
txtReceivedTime .Text = oMsg.ReceivedTi me.ToString();
txtBody.Text = oMsg.Body.ToStr ing();
}
//Log off
oNS.Logoff();
//Clean up
oApp = null;
oNS = null;
oItems = null;
oMsg = null;
*** Sent via Developersdex http://www.developersdex.com ***