Search code examples
c#outlookvstooutlook-addin

How to add custom column in outlook while using DocumentItem


I am developing VSTO addin using C#.

enter image description here

Here, I have drag one file from my PC to outlook folder. It displays in outlook as show in picture.

Now I want to add one column in that folder. I have done some code to add custom column in folder. It will display in picture. Column name is ABCDEFGHI.

I want to update the value of ABCD.pdf file property.

As per outlook ABCD.pdf is a DocumentItem. I want to add my custom property for that file, to display in view.

This is my sample code.

 UserProperties objUserProperties  = objItem.UserProperties;
 UserProperty objUserProperty = objUserProperties.Add("ABCDEFGHI", OlUserPropertyType.olText);
 objt.Value = "YYYY";

This will give me an error.

Error: enter image description here


Solution

  • If you take a look at the UserProperties.Add method description in MSDN you can see the following description:

    You cannot add custom properties to Office document items such as Word, Excel, or PowerPoint files. You will receive an error when you try to programmatically add a user-defined field to a DocumentItem object.

    Instead, I'd recommend creating any Outlook item and attaching a document to it. Following that way you will be able to customize the View by adding user properties as you need.