We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Changing message properties in PST

I want to change message properties for a specific message in PST. As I can see, there is no way to update a message in place in a PST. Is there any work around available for this purpose?

Hi Acton,


Thank you for posting your inquiry.

You can use the FolderInfo.ChangeMessages method to update such messages in a PST file. Please have a look at the following code sample and let us know if you need any further information in this regard.

Sample Code

string dataDir = “Sub.pst”;

// Load the Outlook PST file
PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir);

// Get Requierd Subfolder
FolderInfo inbox = personalStorage.RootFolder.GetSubFolder(“Inbox”);

// find messages having From = "someuser@domain.com"
PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder();
queryBuilder.From.Contains("someuser@domain.com");

// Get Contents from Query
MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery());

// Save (MessageInfo,EntryIdString) in List
IList changeList = new List();
foreach (MessageInfo messageInfo in messages)
{
changeList.Add(messageInfo.EntryIdString);
}

// Compose the new properties
MapiPropertyCollection updatedProperties = new MapiPropertyCollection();
updatedProperties.Add(MapiPropertyTag.PR_SUBJECT_W, new MapiProperty(MapiPropertyTag.PR_SUBJECT_W, Encoding.Unicode.GetBytes(“New Subject”)));
updatedProperties.Add(MapiPropertyTag.PR_IMPORTANCE, new MapiProperty(MapiPropertyTag.PR_IMPORTANCE, BitConverter.GetBytes((long)2)));

// update messages having From = "someuser@domain.com" with new properties
inbox.ChangeMessages(changeList, updatedProperties);