none
How to COPY and PASTE an outlook email from conversation on to C#.Net windows form? RRS feed

  • Question

  • Hi,

    my question is very similar to the one titled "How to COPY and PASTE an outlook email on to C#.Net windows form?". Unfortunately I can't give you a link to it, because my account is not verified yet and your policy not allow me to do so.

    I'm trying to copy e-mail from outlook and then save it as a file. Above solution works perfectly fine except one situation. I have Outlook 2013 and in View I have selected "Show as conversations". When I select and copy conversation and paste it in my application the line: "var item = olApp.Session.GetItemFromID(EntryId);" (I use exactly the same code as in answer in mentioned thread) throws an exception that "something went wrong" and nothing happens. Is it possioble to manage this kind of situation? When I do the same and copy it to windows I actually paste only last e-mail from converastion, I would like to implement something similar. Could you please help me wih this?

    Thank you and best regards,
    Api

    Wednesday, February 5, 2014 11:52 AM

Answers

  • You can use the following code to get the StoreID value:

    Outlook.NameSpace ns = Application.GetNamespace("MAPI");
    Outlook.Stores stores = ns.Stores;
    Outlook.Store store = stores[1];
    
    MessageBox.Show(store.StoreID);

    The value you get in the code is too long for a single item. Did you notice the comma separator?

    I'd recommend splitting the string into separate IDs and then try to use each ID independently. The Split method of the System.String class can be used for separating IDs.


    Wednesday, February 5, 2014 1:33 PM

All replies

  • Hello,

    It looks like you are talking about the How to COPY and PASTE an outlook email on to C#.Net windows form? forum thread.

    Did you try to debug? Did you have a chance to check out the EntryId value?

    The GetItemFromID method of the Namespace class accepts two parameters. Did you try to specify the second one which represents an EntryID value for the store?

    Note, Store's EntryID usually must be provided when retrieving an item based on its MAPI IDs (your case).

    Finally, make sure that you release underlying COM objects instantly. You can read more about this in the Systematically Releasing Objects article in MSDN.

    Wednesday, February 5, 2014 12:13 PM
  • Thank you very much for quick reply.

    Yes, that is the thread I was writing about.

    I've tried to debug the exception message is "Cannot open an element. Try again.". I've checked EntryId, but for me it looks like any other, just some numbers and letters. In this case it is: 0000000022A516771E3FD4438A5BAD740B66224D07006AB75EF6B500E748B5B073C3074B0B9F00000033C3250000505A88CC42CD3748923101D8482467C300003F289C5C0000,0000000022A516771E3FD4438A5BAD740B66224D07006AB75EF6B500E748B5B073C3074B0B9F00000033C3250000505A88CC42CD3748923101D8482467C300003F289C570000

    I've noticed that the method GetItemFromID accepts two parameters, but I don't know how I can get the second one. The first one I'm reading from memory stream: (MemoryStream)Clipboard.GetData("Csv") like in the code provided in answer to the original question. Is there also a way to read a store id from it?
    Wednesday, February 5, 2014 1:01 PM
  • You can use the following code to get the StoreID value:

    Outlook.NameSpace ns = Application.GetNamespace("MAPI");
    Outlook.Stores stores = ns.Stores;
    Outlook.Store store = stores[1];
    
    MessageBox.Show(store.StoreID);

    The value you get in the code is too long for a single item. Did you notice the comma separator?

    I'd recommend splitting the string into separate IDs and then try to use each ID independently. The Split method of the System.String class can be used for separating IDs.


    Wednesday, February 5, 2014 1:33 PM
  • Thank you very much, I didn't notice the comma separator. Now it's working!
    My bad that I didn't check how proper ID looks, I would probably have noticed that this one was too long.
    Wednesday, February 5, 2014 3:38 PM