M
Mike P
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.Application oApp = new Outlook.Application();
//Get MAPI namespace
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon("name", "password", false, true);
//Get Messages collection of Inbox
Outlook.MAPIFolder oInbox =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items oItems = oInbox.Items;
int intTotalNumberOfItemsInInbox = oItems.Count;
//Get unread e-mail messages
oItems = oItems.Restrict("[Unread] = true");
int intTotalUnread = oItems.Count;
//Loop through each unread message
Outlook.MailItem oMsg;
int i;
for (i = 1; i < oItems.Count; i++)
{
oMsg = (Outlook.MailItem)oItems.Item(i);
txtSenderName.Text = oMsg.SenderName.ToString();
txtSubject.Text = oMsg.Subject.ToString();
txtReceivedTime.Text = oMsg.ReceivedTime.ToString();
txtBody.Text = oMsg.Body.ToString();
}
//Log off
oNS.Logoff();
//Clean up
oApp = null;
oNS = null;
oItems = null;
oMsg = null;
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.Application oApp = new Outlook.Application();
//Get MAPI namespace
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
oNS.Logon("name", "password", false, true);
//Get Messages collection of Inbox
Outlook.MAPIFolder oInbox =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items oItems = oInbox.Items;
int intTotalNumberOfItemsInInbox = oItems.Count;
//Get unread e-mail messages
oItems = oItems.Restrict("[Unread] = true");
int intTotalUnread = oItems.Count;
//Loop through each unread message
Outlook.MailItem oMsg;
int i;
for (i = 1; i < oItems.Count; i++)
{
oMsg = (Outlook.MailItem)oItems.Item(i);
txtSenderName.Text = oMsg.SenderName.ToString();
txtSubject.Text = oMsg.Subject.ToString();
txtReceivedTime.Text = oMsg.ReceivedTime.ToString();
txtBody.Text = oMsg.Body.ToString();
}
//Log off
oNS.Logoff();
//Clean up
oApp = null;
oNS = null;
oItems = null;
oMsg = null;