Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / February 2007

Tip: Looking for answers? Try searching our database.

delete property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nikolas - 26 Feb 2007 10:58 GMT
Hi,

Im using VSTO '05 SE with Visual studio '05 on C# to create an add-in for
Outlook '07. I'm trying to delete a property of a mail item using the
PropertyAccessor but I get the following exception:

[System.UnauthorizedAccessException] = {"The property
\"http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/85420003\" does not support this operation."}

Is there a way of deleting this property?

PS. I apologise for posting this question a 2nd time, it was posted on the
wrong section the 1st time.
Sue Mosher [MVP-Outlook] - 26 Feb 2007 14:35 GMT
MAPI properties intrinsic to Outlook can't be deleted with PropertyAccessor. Consider using Redemption instead.

Still the wrong section, BTW. The program_addins and program_vba newsgroups are more appropriate for this type of coding question.
Signature

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
 

> Hi,
>
[quoted text clipped - 9 lines]
> PS. I apologise for posting this question a 2nd time, it was posted on the
> wrong section the 1st time.
Nikolas - 26 Feb 2007 16:08 GMT
Hi Sue, thanks for your response. I'll continue this post here since you got
my attention and is quite urgent to us.

Here is my code trying to delete the property using Redemption:

Type type = Type.GetTypeFromProgID("zetadocsCdo.SafeMailItem");
Redemption.SafeMailItem safeMailItem =
(Redemption.SafeMailItem)Activator.CreateInstance(type);
safeMailItem.AuthKey = "MYKEY";
safeMailItem.Item = mailItem; //the selected item
safeMailItem.set_Fields((Int32)0x80F30003/*85420003*/, 0);
mailItem.Save();

This particular mail item created in Outlook '03 and we want to get rid of
this property (along with others) in order to be able to open it with a form
region in Outlook '07. The strange thing is that if that property doesnt
exist on the mail item then its value is set to 0. If it does exist then its
value does not change.

Also:
long val = (long)safeMailItem.get_Fields(85420003); //fails with exception:
object reference not set to an instance of an object

and:
long val = (long)safeMailItem.get_Fields((Int32)0x80F30003); //does not
compile. Invalid cast

> MAPI properties intrinsic to Outlook can't be deleted with PropertyAccessor. Consider using Redemption instead.
>
[quoted text clipped - 12 lines]
> > PS. I apologise for posting this question a 2nd time, it was posted on the
> > wrong section the 1st time.
Nikolas - 26 Feb 2007 16:18 GMT
Correction:
long val = (long)safeMailItem.get_Fields((Int32)0x80F30003); //it does
compile. But runtime error: Specified cast is not valid

> Hi Sue, thanks for your response. I'll continue this post here since you got
> my attention and is quite urgent to us.
[quoted text clipped - 39 lines]
> > > PS. I apologise for posting this question a 2nd time, it was posted on the
> > > wrong section the 1st time.
Sue Mosher [MVP-Outlook] - 26 Feb 2007 18:59 GMT
Sorry, but I have no expertise in writing C#, only VB/VBA and VBScript.

Why do you need to get rid of the property? I don't see how that would affect the use of a form region.
Signature

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
 

> Hi Sue, thanks for your response. I'll continue this post here since you got
> my attention and is quite urgent to us.
[quoted text clipped - 26 lines]
>>
>> Still the wrong section, BTW. The program_addins and program_vba newsgroups are more appropriate for this type of coding question.

>> > Hi,
>> >
[quoted text clipped - 9 lines]
>> > PS. I apologise for posting this question a 2nd time, it was posted on the
>> > wrong section the 1st time.
Nikolas - 27 Feb 2007 10:16 GMT
I need to delete the one-off properties from the message that was sent from
Outlook 2003. These properties dont let Outlook 2007 use a form region to
open the message.

Is there a reason why I could not possibly delete a property even with
Redemption? Is there a concept of read only properties?

> Sorry, but I have no expertise in writing C#, only VB/VBA and VBScript.
>
[quoted text clipped - 43 lines]
> >> > PS. I apologise for posting this question a 2nd time, it was posted on the
> >> > wrong section the 1st time.
Sue Mosher [MVP-Outlook] - 27 Feb 2007 14:32 GMT
The MAPI properties that make an item an one-off form instance certainly should be removable with Redemption.

Signature

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
 

>I need to delete the one-off properties from the message that was sent from
> Outlook 2003. These properties dont let Outlook 2007 use a form region to
[quoted text clipped - 51 lines]
>> >> > PS. I apologise for posting this question a 2nd time, it was posted on the
>> >> > wrong section the 1st time.
Ken Slovak - [MVP - Outlook] - 27 Feb 2007 15:44 GMT
Since Sue isn't a C# programmer, pardon me for jumping in here.

Never just use a property tag in the 0x80000000 range, it can vary from mail
store to mail store and from store provider to store provider. That
reference you are using to Fields(0x80F30003) is not correct.

For a PT_LONG property like the one you are trying to access in that
namespace you should get the property tag on the fly by using the
SafeMailItem.GetIDsFromNames() method. That returns a 32-bit int and you
then OR that result with the value for PT_LONG (0x0003).

In this case the retrieval of a valid property tag for that property would
look like this:

const int PT_LONG = 0x0003;
int tag =
safeMailItem.GetNamesFromIDs("{00062008-0000-0000-C000-000000000046}",
0x8542) | PT_LONG;

You can then retrieve that property.

If you want to remove it set it to empty.

Signature

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

>I need to delete the one-off properties from the message that was sent from
> Outlook 2003. These properties dont let Outlook 2007 use a form region to
[quoted text clipped - 7 lines]
>> Why do you need to get rid of the property? I don't see how that would
>> affect the use of a form region.
Nikolas - 27 Feb 2007 16:20 GMT
Thanks Ken for your response.

I did what you suggested but Im a bit confused in whats "empty" in C#. I
tried with null and with the value 0 but this didn't delete the property :-/
.

Note that the return int value that I get from
SafeMailItem.GetIDsFromNames() is negative (-2130640896).

> Since Sue isn't a C# programmer, pardon me for jumping in here.
>
[quoted text clipped - 30 lines]
> >> Why do you need to get rid of the property? I don't see how that would
> >> affect the use of a form region.
Ken Slovak - [MVP - Outlook] - 27 Feb 2007 16:40 GMT
A negative value is to be expected. A value of (-2130640896) decimal
translates into a hex value of 0x81010000. That puts that property tag in
the correct range, but it does not have the expected PT_LONG ending of
0x0003. Are you Or'ing the result from GetIdsFromNames() with PT_LONG?

For a PT_LONG (32-bit) I'd expect a property tag of 0x81010003.

If null and 0 don't work does System.Type.Missing work? Or how about
System.Reflection.Missing.Value?

Signature

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

> Thanks Ken for your response.
>
[quoted text clipped - 5 lines]
> Note that the return int value that I get from
> SafeMailItem.GetIDsFromNames() is negative (-2130640896).
Nikolas - 27 Feb 2007 17:28 GMT
grr... Ive spend hours on this. Ok here is my code again:

Type type = Type.GetTypeFromProgID("zetadocsCdo.SafeMailItem");
Redemption.SafeMailItem safeMailItem =
(Redemption.SafeMailItem)Activator.CreateInstance(type);
safeMailItem.AuthKey = "MYKEY";
safeMailItem.Item = mailItem;

const int PT_LONG = 0x0003;

int id =
safeMailItem.GetIDsFromNames("{00062008-0000-0000-C000-000000000046}",
0x8542) | PT_LONG; //id here is: 0x80f30003

safeMailItem.set_Fields(id, System.Reflection.Missing.Value); //tried 0,
null, System.Type.Missing as well.

mailItem.Save(); //do I need that?

I view the properties of the message with OutlookSpy and I see no change. I
can however change the property value with OutlookSpy.

> A negative value is to be expected. A value of (-2130640896) decimal
> translates into a hex value of 0x81010000. That puts that property tag in
[quoted text clipped - 15 lines]
> > Note that the return int value that I get from
> > SafeMailItem.GetIDsFromNames() is negative (-2130640896).
Ken Slovak - [MVP - Outlook] - 27 Feb 2007 19:47 GMT
OK, that looks all right.

Can you set that long property to a value of 0? Or any other integer value?
Let's leave aside deleting it for the moment, first make sure you can
actually set it to something.

If you are going to save the underlying MailItem, recommended, first try
something like:

   mailItem.Subject = mailItem.Subject;

That will fake Outlook into thinking something has changed so it will update
everything.

Signature

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

> grr... Ive spend hours on this. Ok here is my code again:
>
[quoted text clipped - 18 lines]
> I
> can however change the property value with OutlookSpy.
Nikolas - 28 Feb 2007 14:23 GMT
Yes that did the trick. I was looking how to set the mailItem to "dirty" but
there isnt such a function and I assumed that it sets it automatically.
Setting the subject fixed it.

Thanks for your help.

> OK, that looks all right.
>
[quoted text clipped - 32 lines]
> > I
> > can however change the property value with OutlookSpy.
Ken Slovak - [MVP - Outlook] - 28 Feb 2007 19:53 GMT
Changes you make to an item using MAPI (or Redemption) will not be visible
right away in Outlook unless you tell Outlook that something has changed.
That little trick with item.Subject does just that. Outlook isn't aware on
its own of changes you make to opened items using MAPI unless you use a
trick like that.

Signature

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

> Yes that did the trick. I was looking how to set the mailItem to "dirty"
> but
> there isnt such a function and I assumed that it sets it automatically.
> Setting the subject fixed it.
>
> Thanks for your help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.