Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: Deleted Items

Geek News

Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/6/2006 4:36:31 PM
Hey guys, I want to check if an item exists in the DeletedItems Folder,
but if I use item.Parent, it will show me the original folder of the
item. So if I delete a task through outlook UI, and then in my code
check the Parent it will still show as Tasks until I shutdown outlook
and restart. It is like it does not pick up the fact that this item is
in the Deleted Items folder until I restart outlook. I do not want to
enumerate through all of the deleted items each time, so do you have any
suggestions?
Thanks
Re: Deleted Items
"Sue Mosher [MVP-Outlook]" <suemvp[ at ]outlookcode.com> 3/6/2006 5:12:39 PM
Please show the code you're using the access the item and explain what event you're using to run it.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:%237idgwTQGHA.3192[ at ]TK2MSFTNGP09.phx.gbl...
[Quoted Text]
> Hey guys, I want to check if an item exists in the DeletedItems Folder,
> but if I use item.Parent, it will show me the original folder of the
> item. So if I delete a task through outlook UI, and then in my code
> check the Parent it will still show as Tasks until I shutdown outlook
> and restart. It is like it does not pick up the fact that this item is
> in the Deleted Items folder until I restart outlook. I do not want to
> enumerate through all of the deleted items each time, so do you have any
> suggestions?
> Thanks
Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/7/2006 12:48:22 AM
Thanks as always Sue:

Outlook.MAPIFolder mFolder
=(Outlook.MAPIFolder)HelperClass.GetPropertyHelper(item, "Parent");
string fname = mFolder.Name;

if(fname.IndexOf("Deleted") >= 0)
{

}

"fname" seems to be the original folder that the item was deleted from,
not the deleted items folder. If I close outlook and restart then it
picks up.
I am running this code on a button click not on any outlook event.
Rog

Sue Mosher [MVP-Outlook] wrote:
[Quoted Text]
> Please show the code you're using the access the item and explain what event you're using to run it.
>
Re: Deleted Items
"Sue Mosher [MVP-Outlook]" <suemvp[ at ]outlookcode.com> 3/7/2006 1:36:06 AM
How does GetPropertyHelper work? And how -- and when -- is Item instantiated?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:440CD856.1070306[ at ]yahoo.com...
[Quoted Text]
> Thanks as always Sue:
>
> Outlook.MAPIFolder mFolder
> =(Outlook.MAPIFolder)HelperClass.GetPropertyHelper(item, "Parent");
> string fname = mFolder.Name;
>
> if(fname.IndexOf("Deleted") >= 0)
> {
>
> }
>
> "fname" seems to be the original folder that the item was deleted from,
> not the deleted items folder. If I close outlook and restart then it
> picks up.
> I am running this code on a button click not on any outlook event.

> Hey guys, I want to check if an item exists in the DeletedItems Folder,
> but if I use item.Parent, it will show me the original folder of the
> item. So if I delete a task through outlook UI, and then in my code
> check the Parent it will still show as Tasks until I shutdown outlook
> and restart. It is like it does not pick up the fact that this item is
> in the Deleted Items folder until I restart outlook. I do not want to
> enumerate through all of the deleted items each time, so do you have any
> suggestions?
> Thanks
Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/7/2006 1:39:56 PM
public static object GetPropertyHelper(object targetObject, string
propertyName)
{
try
{
return targetObject.GetType().InvokeMember(propertyName,
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.GetProperty,
null,
targetObject,
null,
System.Globalization.CultureInfo.CurrentCulture);
}
catch(System.Exception ex)
{
GlobalConstants.Log(log, "Error", "GetPropertyHelper", ex);
return null;
}
}

and
object item =
this.OutlookApp.GetNamespace("MAPI").GetItemFromID(entryID, storeID);

Thanks so much.

Sue Mosher [MVP-Outlook] wrote:
[Quoted Text]
> How does GetPropertyHelper work? And how -- and when -- is Item instantiated?
>
Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/7/2006 2:31:13 PM
I even tried using redemption and getting property 0x0E090102 but it
returns the entryid of the contacts folder (where it was deleted from)
not the entryid of the deleted items folder. but if I use OutlookSpy and
look at 0x0E090102 property then it shows the entryid of the Deleted
Items folder for that Contact.

Rog wrote:
[Quoted Text]
> public static object GetPropertyHelper(object targetObject,
> string propertyName)
> {
> try
> {
> return targetObject.GetType().InvokeMember(propertyName,
> System.Reflection.BindingFlags.Public |
> System.Reflection.BindingFlags.Instance |
> System.Reflection.BindingFlags.GetProperty,
> null,
> targetObject,
> null,
> System.Globalization.CultureInfo.CurrentCulture);
> }
> catch(System.Exception ex)
> {
> GlobalConstants.Log(log, "Error", "GetPropertyHelper", ex);
> return null;
> }
> }
>
> and
> object item =
> this.OutlookApp.GetNamespace("MAPI").GetItemFromID(entryID, storeID);
>
> Thanks so much.
>
> Sue Mosher [MVP-Outlook] wrote:
>> How does GetPropertyHelper work? And how -- and when -- is Item
>> instantiated?
Re: Deleted Items
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/7/2006 2:36:49 PM
Have you released all references to the original object and since you're
using .NET code also called Marshal.ReleaseCOMObject and called the garbage
collector? Outlook caches items and their properties and the fact that
things work if you close and restart Outlook makes it look like it's a
caching problem. As long as an item is cached it will return its original
properties back.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:440D9931.8080802[ at ]yahoo.com...
[Quoted Text]
>I even tried using redemption and getting property 0x0E090102 but it
>returns the entryid of the contacts folder (where it was deleted from) not
>the entryid of the deleted items folder. but if I use OutlookSpy and look
>at 0x0E090102 property then it shows the entryid of the Deleted Items
>folder for that Contact.
>
> Rog wrote:
>> public static object GetPropertyHelper(object targetObject,
>> string propertyName)
>> {
>> try
>> {
>> return targetObject.GetType().InvokeMember(propertyName,
>> System.Reflection.BindingFlags.Public |
>> System.Reflection.BindingFlags.Instance |
>> System.Reflection.BindingFlags.GetProperty,
>> null,
>> targetObject,
>> null,
>> System.Globalization.CultureInfo.CurrentCulture);
>> }
>> catch(System.Exception ex)
>> {
>> GlobalConstants.Log(log, "Error", "GetPropertyHelper",
>> ex);
>> return null;
>> }
>> }
>>
>> and
>> object item = this.OutlookApp.GetNamespace("MAPI").GetItemFromID(entryID,
>> storeID);
>>
>> Thanks so much.
>>
>> Sue Mosher [MVP-Outlook] wrote:
>>> How does GetPropertyHelper work? And how -- and when -- is Item
>>> instantiated?

Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/7/2006 4:06:43 PM
Thanks Ken for your help on this.
Only problem is I do not maintain a reference to this contact until I am
trying to find it when the button is clicked:
I use this code to get the object:
object item =
this.OutlookApp.GetNamespace("MAPI").GetItemFromID(entryID, storeID);
but I do not maintain a reference to item outside of this function call.

If I get the item as above and then call:
System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
GC.Collect();
GC.WaitForPendingFinalizers();

it does not seem to do anything about releasing the cache.
Any ideas?
Thanks so much as always

Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text]
> Have you released all references to the original object and since you're
> using .NET code also called Marshal.ReleaseCOMObject and called the
> garbage collector? Outlook caches items and their properties and the
> fact that things work if you close and restart Outlook makes it look
> like it's a caching problem. As long as an item is cached it will return
> its original properties back.
>
Re: Deleted Items
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/7/2006 10:32:47 PM
Well, I'm sorry to tell you nothing really looks wrong in your code :)

The only thing I can think of and it's a stretch, is that you might try
getting each component object as a separate object instead of using dot
operators, where Outlook always creates internal variables. So for example
set a NameSpace object and use that to call the GetItemFromID method. Also
see if you are doing anything further on in that code that might call a
procedure or item method that somehow might also be creating an implicit
object variable that isn't being released when expected.

I'd also be curious to see if you put up some button or something and waited
a while, like 5 minutes, before clicking it and seeing if the GetItemFromID
code worked then. Just for testing of course.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:440DAF93.2030906[ at ]yahoo.com...
[Quoted Text]
> Thanks Ken for your help on this.
> Only problem is I do not maintain a reference to this contact until I am
> trying to find it when the button is clicked:
> I use this code to get the object:
> object item = this.OutlookApp.GetNamespace("MAPI").GetItemFromID(entryID,
> storeID);
> but I do not maintain a reference to item outside of this function call.
>
> If I get the item as above and then call:
> System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
> GC.Collect();
> GC.WaitForPendingFinalizers();
>
> it does not seem to do anything about releasing the cache.
> Any ideas?
> Thanks so much as always

Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/8/2006 3:52:40 PM
Yes it seems if I do wait some period of time after deleting an item
from the contacts folder it will be picked up that it has moved into the
Deleted Items Folder.
What is odd too is, I used OutlookSpy to look at PR_PARENT_ENTRYID and
it shows the deleted items folder enntry, but if I use the same in my code:
safeMailitem.get_Fields(235471106); it will return the entryid of the
Contacts folder.


Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text]
> Well, I'm sorry to tell you nothing really looks wrong in your code :)
>
> The only thing I can think of and it's a stretch, is that you might try
> getting each component object as a separate object instead of using dot
> operators, where Outlook always creates internal variables. So for
> example set a NameSpace object and use that to call the GetItemFromID
> method. Also see if you are doing anything further on in that code that
> might call a procedure or item method that somehow might also be
> creating an implicit object variable that isn't being released when
> expected.
>
> I'd also be curious to see if you put up some button or something and
> waited a while, like 5 minutes, before clicking it and seeing if the
> GetItemFromID code worked then. Just for testing of course.
>
Re: Deleted Items
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/8/2006 4:03:26 PM
All that means is that something is holding a reference to the original item
and it's taking a while for it to go away. That's classic behavior for
something that's finally getting hit by the garbage collector and not being
fully released until then. You're going to have to put your detective's hat
on to find what that is.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:440EFDC8.9010800[ at ]yahoo.com...
[Quoted Text]
> Yes it seems if I do wait some period of time after deleting an item from
> the contacts folder it will be picked up that it has moved into the
> Deleted Items Folder.
> What is odd too is, I used OutlookSpy to look at PR_PARENT_ENTRYID and it
> shows the deleted items folder enntry, but if I use the same in my code:
> safeMailitem.get_Fields(235471106); it will return the entryid of the
> Contacts folder.

Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/8/2006 5:40:33 PM
thanks Ken, do you have any suggestions or tools that may help me to
figure that out?

Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text]
> All that means is that something is holding a reference to the original
> item and it's taking a while for it to go away. That's classic behavior
> for something that's finally getting hit by the garbage collector and
> not being fully released until then. You're going to have to put your
> detective's hat on to find what that is.
>
Re: Deleted Items
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/9/2006 2:27:18 PM
No, not really. It's a matter of looking over each line of your code with a
microscope and checking for creation of implicit variables (from using
compound dot operators instead of explicitly declared variables for each dot
operator), making sure everything is explicitly released instead of relying
on things to go out of scope and other best practices.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:440F1711.50205[ at ]yahoo.com...
[Quoted Text]
> thanks Ken, do you have any suggestions or tools that may help me to
> figure that out?

Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/9/2006 4:20:41 PM
OK so for example if I get a list of contacts like
GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts).Items;
and I use it, do I need to release it when I am done with these items?
Also if I say:
object item = GetFolderFromId(entry, store);
do I need to release this item and garbage collect everytime when I am
done with it?
rog

Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text]
> No, not really. It's a matter of looking over each line of your code
> with a microscope and checking for creation of implicit variables (from
> using compound dot operators instead of explicitly declared variables
> for each dot operator), making sure everything is explicitly released
> instead of relying on things to go out of scope and other best practices.
>
Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/9/2006 4:21:53 PM
Also do you have a place to go where I can learn these best practices?
Rog

Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text]
> No, not really. It's a matter of looking over each line of your code
> with a microscope and checking for creation of implicit variables (from
> using compound dot operators instead of explicitly declared variables
> for each dot operator), making sure everything is explicitly released
> instead of relying on things to go out of scope and other best practices.
>
Re: Deleted Items
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/9/2006 5:16:02 PM
I would break that up so no implicit object variables are created. In VB 6
syntax:

Dim oNS As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim colItems As Outlook.Items

Set oNS = oOL.GetNameSpace("MAPI")
Set oFolder = oNS.GetDefaultFolder(olFolderContacts)
Set colItems = oFolder.Items

I would explicitly release objects as soon as they are no longer needed. I
would minimize the calls to the garbage collector until they are needed,
perhaps in the shutdown code and whenever you need to ensure that no cached
object references are being maintained.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:441055D9.7030000[ at ]yahoo.com...
[Quoted Text]
> OK so for example if I get a list of contacts like
> GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts).Items;
> and I use it, do I need to release it when I am done with these items?
> Also if I say:
> object item = GetFolderFromId(entry, store);
> do I need to release this item and garbage collect everytime when I am
> done with it?
> rog

Re: Deleted Items
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/9/2006 5:16:46 PM
Look at the information at
http://www.microeye.com/resources/res_outlookvsnet.htm

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rog" <rog_21[ at ]yahoo.com> wrote in message news:44105621.6060300[ at ]yahoo.com...
[Quoted Text]
> Also do you have a place to go where I can learn these best practices?
> Rog
>
> Ken Slovak - [MVP - Outlook] wrote:
>> No, not really. It's a matter of looking over each line of your code with
>> a microscope and checking for creation of implicit variables (from using
>> compound dot operators instead of explicitly declared variables for each
>> dot operator), making sure everything is explicitly released instead of
>> relying on things to go out of scope and other best practices.
>>

Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/10/2006 8:58:17 PM
As always thank you Ken.
I am wondering I tried adding:
try
{
while
(System.Runtime.InteropServices.Marshal.ReleaseComObject(contactItem) > 0);
contactItem = null;
}
catch(System.Exception ex)
{
GlobalConstants.Log(log, "Error", "ReleasingComObjects", ex);
}

but sometimes it seems that while I am trying to do my processing I lose
reference to my object even though it was created after this.
Any ideas?
Thanks,
Rog
Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text]
Re: Deleted Items
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/13/2006 3:47:59 PM
I have no idea.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rog" <rog_21[ at ]yahoo.com> wrote in message
news:eWMEdVIRGHA.5636[ at ]TK2MSFTNGP10.phx.gbl...
[Quoted Text]
> As always thank you Ken.
> I am wondering I tried adding:
> try
> {
> while
> (System.Runtime.InteropServices.Marshal.ReleaseComObject(contactItem) >
> 0);
> contactItem = null;
> }
> catch(System.Exception ex)
> {
> GlobalConstants.Log(log, "Error", "ReleasingComObjects", ex);
> }
>
> but sometimes it seems that while I am trying to do my processing I lose
> reference to my object even though it was created after this.
> Any ideas?
> Thanks,
> Rog

Re: Deleted Items
Rog <rog_21[ at ]yahoo.com> 3/16/2006 2:50:38 PM
Just an update:
Thanks so Ken and Dmitry's guidance I have solved the deleted items problem
It definately was items being held in memory.
The point where I found where my items were being held in memory was
when I use the InspectorWrapper. On close of the inspector I was not
releasing the items from memory.
Thanks guys.


Ken Slovak - [MVP - Outlook] wrote:
[Quoted Text]
> I have no idea.
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net