DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Outlook.Selection: determine what type of item is selected. (http://www.daniweb.com/forums/thread159522.html)

murderotica Nov 26th, 2008 1:11 am
Outlook.Selection: determine what type of item is selected.
 
Hello there, I've been doing some research about the Outlook.Selection interface and made an application out of it. My goal is to get all of the items in my inbox folder. I have already created a way to get all of them, my problem is to filter each types of items in my inbox. I found a link that could handle it but it is written in VB. It has all of the information that I needed but it seems that I can't get the MessageClass of the variable which is of type Object. Here is the link: http://support.microsoft.com/kb/240935

This is exactly what I want my filtering to be in C#. Any thoughts and suggestions I would really appreciate. Thank you.

LizR Nov 26th, 2008 4:37 am
Re: Outlook.Selection: determine what type of item is selected.
 
Accessing mails from outlooks inbox is generally quite simple and mine seems to pick up the differences. What code do you have as while I didnt derrive mine from that vb, mine uses pretty much the same concept.

murderotica Nov 26th, 2008 5:52 am
Re: Outlook.Selection: determine what type of item is selected.
 
Thanks for the reply. I'm using VSTO Sir. My only problem right now is to filter the items that I'm dragging (whether it is a MailItem, MeetingItem, AppointmenItem etc.). The sample code in the link uses MessageClass which he got from the variable of type Object which contains the item selected in the ActiveExplorer. I think C# has a different way of getting the MessageClass which is I'm not that really familiar.

LizR Nov 26th, 2008 6:13 am
Re: Outlook.Selection: determine what type of item is selected.
 
Frirstly, Im not male. Please do not make such rash assumptions.

Secondly, Ive asked for some code as it would seem you've approached it very differently from me as all items correctly report their code for me, and perhaps you're going about it the wrong way.

murderotica Nov 26th, 2008 10:41 pm
Re: Outlook.Selection: determine what type of item is selected.
 
I'm so sorry, I didn't mean it. This is my test program seperated from my application.

 private void Form1_Load(object sender, EventArgs e)
 {
  Outlook.Application app = new Outlook.Application();
            Outlook.NameSpace nmspc = app.GetNamespace("mapi");
            Outlook.MAPIFolder inbox = nmspc.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

         
            Outlook.MeetingItem item;
            for (int i = 8; i < 9; i++)
          {
                item = (Outlook.MeetingItem)inbox.Items[i];
                item.SaveAs(@"c:\TempFile\Temp" + item.EntryID.ToString() + ".msg", Outlook.OlSaveAsType.olMSG);
                MessageBox.Show(item.EntryID.ToString());
            }
         
 }

This is just a test sample because I don't want to mess the whole application that I made. This is my way of getting all the items in my inbox. All I need is a filtering to determine if it is a MailItem, ApplicationItem, MeetingItem etc.

LizR Nov 27th, 2008 3:20 am
Re: Outlook.Selection: determine what type of item is selected.
 
OK, but that will pick up only meeting items, as you cant assign mail items to a meetingitem, it will cause an exception. the messageclass property is text and will confirm then which subtype of the item you picked is, such as out of office etc.

murderotica Nov 27th, 2008 3:35 am
Re: Outlook.Selection: determine what type of item is selected.
 
I agree that MessageClass property will confirm which subtype is picked but I'm having a problem how to use it in C#.

LizR Nov 27th, 2008 4:09 am
Re: Outlook.Selection: determine what type of item is selected.
 
Its a string, it will give you in words the type.

PS - just like in the vb example you posted

murderotica Nov 27th, 2008 4:21 am
Re: Outlook.Selection: determine what type of item is selected.
 
The line
 strMessageClass = oItem.MessageClass
seems does not work in C#. oItem is of type Object. It throws an error.

LizR Nov 27th, 2008 4:29 am
Re: Outlook.Selection: determine what type of item is selected.
 
In your code above, "Outlook.MeetingItem item" as long as you called item.MessageClass you would be ok.


All times are GMT -4. The time now is 12:06 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC