DocumentItem throws exception if trying to add user property in that.
We are customizing the outlook view by adding some userdefined property in the MailItems and it worked fine.
When we also do the same with DocumentItem, it generates exception that "user property is read-only"
Since we have to provide some of the user defined values with document item, we have to add some user defined property which we can shows by customizing the view.
as i google i found that it is restricted by Outlook object model but this could be override by redeemption, but dont know how. Please find my code below which i am using to add the user properties to document item.
var docitem = folder.CreateItem("IPM.Document") as DocumentItem;
if (docitem != null)
{
docitem.Subject = "this is test doc file";docitem.UserProperties.Add("prop1", OlUserPropertyType.olText, true).value = "x";
docitem.UserProperties.Add("prop2", OlUserPropertyType.olText, true).value = "y";//some code below to add the attachment document in this
!------------//if attachment is not sucessfull, no need to save the document mail item
if (attachment == null)
break;//code to change the attached message class based on its filetype
docitem = AttachmentHelper.AssociateDocumentClass(Filtype, docitem);docitem.UnRead = true;
docitem.Save();
}
Answers
Hi,
i had find out the solution for that from redeemption API. I really thanks to Dmitry and Samuel who really help me to get out of this problem.
We had create an extenstion method to DocumentItem
public static void SetDocumentProperty(this _DocumentItem docItem, string propertyName, string value)
{
const string yourCustomGuid = "{00020329-0000-0000-C000-000000000046}";
// Get existing / create new named property.
SafeMailItem safeItem = new SafeMailItemClass {Item = docItem};
var propId = safeItem.GetIDsFromNames(yourCustomGuid, propertyName);
// PT_STRING8 == 0x0000001E
propId = propId | 0x1e;
safeItem.set_Fields(propId, value);
docItem.Save();
}and used it to add the properties to document item like that
docitem.SetDocumentProperty("prop1", "valu1");- Edited byvijay kumar anand Saturday, November 07, 2009 2:25 PMcode copy mistake
- Marked As Answer byvijay kumar anand Saturday, November 07, 2009 2:24 PM
All Replies
Hi,
i had find out the solution for that from redeemption API. I really thanks to Dmitry and Samuel who really help me to get out of this problem.
We had create an extenstion method to DocumentItem
public static void SetDocumentProperty(this _DocumentItem docItem, string propertyName, string value)
{
const string yourCustomGuid = "{00020329-0000-0000-C000-000000000046}";
// Get existing / create new named property.
SafeMailItem safeItem = new SafeMailItemClass {Item = docItem};
var propId = safeItem.GetIDsFromNames(yourCustomGuid, propertyName);
// PT_STRING8 == 0x0000001E
propId = propId | 0x1e;
safeItem.set_Fields(propId, value);
docItem.Save();
}and used it to add the properties to document item like that
docitem.SetDocumentProperty("prop1", "valu1");- Edited byvijay kumar anand Saturday, November 07, 2009 2:25 PMcode copy mistake
- Marked As Answer byvijay kumar anand Saturday, November 07, 2009 2:24 PM
- Thank you very much for taking a moment to come back and report this. I'm sure this will help others in the future.
Best regards,
Bessie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


