Outlook MAPI Folder Items cannot be cast

M

Matthew Gibson

I have written a small app in C# that scans through an Outlook folders
items. I have the items saved in a local variable, however when i retrieve
the items from the items collection and cast it to a TaskItem it always
comes back as null.

Here is the code
-----------------------------------------------------------------------------------------------------------------------------------------------------------
oNameSpace.Folders["Mailbox - Matthew Gibson"].Folders["Client
Licences"].CopyTo(oLicenceFolder);
oProcessedFolder = oNameSpace.Folders["Mailbox - Matthew
Gibson"].Folders["Processed"];
Microsoft.Office.Interop.Outlook.Items myItems = oLicenceFolder.Items;
//myItems = myItems.Restrict("[MessageClass] =
'IPM.Task.ClientLic29012004'");
int count = myItems.Count;

if (count > 0)
{
txtOutlook.Text = "Items in Licence folder: " + count.ToString();
txtOutlook.Refresh();
int lvi = 0;
int lviInvalidCast =0;
int lviMethodFailed =0;
int lviProcessed = 0;
int lviNullItems = 0;

foreach(object obj in myItems)

{

lvi++;

lblRecord.Text = "Record: " + lvi.ToString();

lblRecord.Refresh();


Microsoft.Office.Interop.Outlook.TaskItem item = obj as
Microsoft.Office.Interop.Outlook.TaskItem;


if (item != null)

{

-----------------------------------------------------------------------------------------------------------------------------------------------------------

The variable 'item' sometimes casts to a TaskItem correctly but the majority
of the time it becomes null. I have tried casting it to all of the other
Outlook Item types, ie MailItem etc, however they are allways returned as
null from casting using the 'as' operator.

Can anybody suggest why this is the case? and provide a code example?

Many Thanks

Matt Gibson

(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top