Question

I have some code:

Outlook.Application outLookApp = new Outlook.Application();
Outlook.Inspector inspector = outLookApp.ActiveInspector();
Outlook.NameSpace nameSpace = outLookApp.GetNamespace("MAPI");
Outlook.MAPIFolder inbox = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
String sCriteria = "[SenderEmailAddress] = 'somebody@somewhare.com'";
Outlook.Items filteredItems = inbox.Items.Restrict(sCriteria);
// totaly sure that count > 0;
Outlook.MailItem item = filteredItems[1];

In the last line I have error: "Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Outlook.MailItem'. An explicit conversion exists (are you missing a cast?)". I don't know why. Previous I used VisualStudio 2010 but my trial has expired. Is there any hope to run this on SharpDevelop?

Was it helpful?

Solution

This doesn't look like a SharpDevelop error, it looks like you just need a cast. Try this:

Outlook.MailItem item = (Outlook.MailItem)filteredItems[1];

(this is assuming that the objects in filteredItems are actually of this type. You may want to test if this is the case before this assignment.)

Also, you could use Visual Studio 2010 Express - http://www.microsoft.com/express/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top