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

Free Support Forum - aspose.com

Create property across all item types

Is it possible to create an extended property across all item types ie MapiContact, MapiCalendar, MapiMessage.


I can see MapiMessage has AddCustomProperty. is there anything that can be used across every item?

I would like to create a property/field and store my own item id for each item created in a PST file. Can this also be done for a folder?

I’m currently reviewing this product on a trial.

Thanks

Hi Ashley,


Thank you for contacting Aspose support team.

You may please use functions like AddCustomProperty(), SetProperty() and Properties.Add() functions to set custom properties, as shown in the following sample code. It adds properties to MapiMessage, MapiCalendar, MapiContact and folder.


string YOUR_DATA_STRING = “This
is a simple data text which is set by user.”
;<o:p></o:p>

MapiMessage mapi1 = new MapiMessage("from@domain.com", "to@domain.com", "Subject", "Body");

long tag = mapi1.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE);

MapiProperty property = new MapiProperty(tag,Encoding.Unicode.GetBytes(YOUR_DATA_STRING));

mapi1.AddCustomProperty(property, "StringProp");

MapiContact contact1 = new MapiContact("Sebastian Wright", "SebastianWright@dayrep.com");

contact1.SetProperty(property);

MapiCalendar calendar1 = new MapiCalendar("Location", "Summary", "Description", new DateTime(2015, 7, 28), new DateTime(2015, 7, 29));

calendar1.SetProperty(property);

if (File.Exists("output21.pst"))

File.Delete("output21.pst");

PersonalStorage pst = PersonalStorage.Create("output21.pst", FileFormatVersion.Unicode);

FolderInfo info = pst.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox);

info.Properties.Add(tag, property);

Thanks for getting back to me and the code sample.

I’m trying the the following:
private static void ReadFolder(MapiMessage mapi1, long tag, MapiProperty property) {
using (PersonalStorage pst = PersonalStorage.FromFile(_pstPath)) {
FolderInfo folderInfo = pst.RootFolder.GetSubFolder(“Contacts”);
FolderInfo subFolderInfo = folderInfo.GetSubFolder(“Sub Folder”);
foreach (DictionaryEntry entry in subFolderInfo.Properties) {
Console.WriteLine(entry.Key + “|” + entry.Value);
}
Console.WriteLine(Environment.NewLine);
}
}

private static void AddFolder(MapiMessage mapi1, long tag, MapiProperty property) {
using (PersonalStorage pst = PersonalStorage.FromFile(_pstPath)) {
mapi1.AddCustomProperty(property, “StringProp”);
FolderInfo folderInfo = pst.RootFolder.GetSubFolder(“Contacts”);
FolderInfo subFolderInfo = folderInfo.GetSubFolder(“Sub Folder”);
if (subFolderInfo == null) {
subFolderInfo = folderInfo.AddSubFolder(“Sub Folder”, “IPF.Contact”);
}
subFolderInfo.Properties.Add(tag, property);
foreach (DictionaryEntry entry in subFolderInfo.Properties) {
Console.WriteLine(entry.Key + “|” + entry.Value);
}
Console.WriteLine(Environment.NewLine);
}
}

when I add the property I can see the value, when I come to read that folder again the property is not displayed. Do I need to doing anything else to save the property?

If i add the following AddFolder:
subFolderInfo.AddMessage(mapi1);

It appears to have saved the property, however I have an empty contact entry in that folder.

Thanks


Hi Ashley,


We have analyzed the issue and observed that PST folder does not support adding named property. I have logged a ticket under id: EMAILNET-34931:“Create named property in PST folder” for further investigation by the product team. I shall write here as soon as some feedback is received in this regard.

Not, sure what happened. Appears my reply to the last post on this thread has disappeared. Will try again :slight_smile:

I’ve tried adding a property to a MapiContact and it does not appear to work or give the desired results, it appears the tag with. [Here is a screen shot:](http://images.devs-on.net/Image/5yK1Go10DftQCMwH-fileCProjectsAs.png) At the top of the screen you will see the tag id and the value it should contain, when I look at the corresponding tag in the properties it has another value

private static void Main(string[] args) {

string id = “thisismyid”;

MapiMessage mapi1 = new MapiMessage();

long tag = mapi1.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE);

MapiProperty property = new MapiProperty(tag, Encoding.Unicode.GetBytes(id));

if (!File.Exists(_pstPath)) {

using (PersonalStorage pst = PersonalStorage.Create(_pstPath, FileFormatVersion.Unicode)) {

FolderInfo folder = pst.CreatePredefinedFolder(“Contacts”, StandardIpmFolder.Contacts);

Console.WriteLine(folder.EntryIdString);

Add(mapi1, tag, property, pst);

Read(mapi1, tag, property, pst);

}

} else {

using (PersonalStorage pst = PersonalStorage.FromFile(_pstPath)) {

Read(mapi1, tag, property, pst);

}

}

Console.ReadKey();

}

private static void Read(MapiMessage mapi1, long tag, MapiProperty property, PersonalStorage pst) {

FolderInfo folderInfo = pst.RootFolder.GetSubFolder(“Contacts”);

FolderInfo subFolderInfo = folderInfo.GetSubFolder(“Sub Folder”);

MessageInfoCollection coll = subFolderInfo.GetContents();

Console.WriteLine(“TAG : " + tag);

foreach (MessageInfo messageInfo in coll) {

MapiContact contact = (MapiContact)pst.ExtractMessage(messageInfo).ToMapiMessageItem();

foreach (DictionaryEntry entry in contact.Properties) {

Console.WriteLine(entry.Key + “|” + entry.Value);

}

}

Console.WriteLine(Environment.NewLine);

}

private static void Add(MapiMessage mapi1, long tag, MapiProperty property, PersonalStorage pst) {

mapi1.AddCustomProperty(property, “StringProp”);

FolderInfo folderInfo = pst.RootFolder.GetSubFolder(“Contacts”);

FolderInfo subFolderInfo = folderInfo.GetSubFolder(“Sub Folder”);

if (subFolderInfo == null) {

subFolderInfo = folderInfo.AddSubFolder(“Sub Folder”, “IPF.Contact”);

}

MapiContact contact1 = new MapiContact(“Sebastian Wright”, "SebastianWright@dayrep.com”);

contact1.SetProperty(property);

subFolderInfo.AddMapiMessageItem(contact1);

Console.WriteLine(Environment.NewLine);

}

Hi Ashley,


This was a separate issue that you reported under the same thread. We split it earlier and created a new thread of it that you can follow here. The issue has already been reported as EMAILNET-34935 to our product team and we shall share the update with you once available. Please feel free to write to us if you have any other query related to Aspose.Email API.

Thanks, I didn’t get any email notifying me that it had been created.


I’ve tested the following on MapiCalendar and it doesn’t even appear to create or populate the property. I did test this very quickly though. It does work for MapiMessage.

Thanks again for all your help

Not sure whats going on here, I’m using the following code:

MapiMessage mapiMessage = new MapiMessage();

long tag = mapiMessage.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE);

return tag;

This returns the following : 2147483679

I use the following to set the value :

MapiProperty TagItem(string id) {

long tag = GetTag();

return new MapiProperty(tag, Encoding.Unicode.GetBytes(id));

}

Message.SetProperty(TagItem(“myid”));

At this point just before adding the item I checked the NameProperties I can see my id under [2147483678](http://images.devs-on.net/Image/9WA6YPpvCltbHXZS-Region.png)

When I go to read the contents of the PST and try and retrieve the id it appears under [2147614751](http://images.devs-on.net/Image/LuUgdePJ4Hj7mtR7-Region.png)

My previous test was done on a very basic mapi message, Is this a bug?

Thanks

Hi Ashley,


We consider this to be somewhat similar behavior to EMAILNET-34931 as the properties are not retained for the PST items. We may further investigate the problem once the above investigation ticket is looked into by our Product team. We shall share our feedback with you once it is done.
Hello Ashley,

This is not a bug. Property id of named properties (its' mapi property tag) changes depending on either a msg is stored in pst or is separately in a file. Named properties aren't differentiated by a property id (mapi property tag), but by their name.

Thanks.
Ok, so how do I get the value I have stored then if the tag is not the same as the tag generated. I get 2147483679 but it appears in 2147483678.

When I close my test application and try and read the pst and get the id of the message I have just added I can see my id stored in 2147614751.

At the end of day, all i want to do is store an idea against MapiMessage or other Mapi items and be able to retrieve it. Can this be done in a consistent way? Thanks

Hi Ashley,


As mentioned by Dmitry, nammed properties are differentiated by their names. You can use the following sample code to find the property that you have set.

Code:

MapiMessage msg = new MapiMessage("user1@gmail.com", "user2@gmail.com", “Sample Subject”, “Sample Body”);<o:p></o:p>

MapiNamedPropertyMappingStorage mappingStorage = msg.NamedPropertyMapping;

//Set property 1

Guid PS_PUBLIC_STRINGS = new Guid("00020329-0000-0000-C000-000000000046");

MapiProperty stringProperty = new MapiProperty(mappingStorage.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE), Encoding.Unicode.GetBytes("test1"));

msg.SetProperty(stringProperty);

string stringNameId = "Archive ID";

mappingStorage.AddNamedPropertyMapping(stringProperty, stringNameId, PS_PUBLIC_STRINGS);

//Set property 2

Guid PS_PUBLIC_STRINGS2 = new Guid("00020329-0000-0000-C000-000000000047");

MapiProperty stringProperty2 = new MapiProperty(mappingStorage.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE), Encoding.Unicode.GetBytes("test2"));

msg.SetProperty(stringProperty2);

string stringNameId2 = "Saveset ID";

mappingStorage.AddNamedPropertyMapping(stringProperty2, stringNameId2, PS_PUBLIC_STRINGS);

msg.Save(@"test.msg");

MapiMessage msgSaved = MapiMessage.FromFile(@"test.msg");

// Get all named MAPI properties

MapiPropertyCollection properties = msgSaved.NamedProperties;

// Read all properties in foreach loop

foreach (MapiNamedProperty mapiNamedProp in properties.Values)

{

// Read any specific property

switch (mapiNamedProp.NameId)

{

case "Archive ID":

Console.WriteLine("{0} = {1}", mapiNamedProp.NameId, mapiNamedProp.GetString());

break;

case "Saveset ID":

Console.WriteLine("{0} = {1}", mapiNamedProp.NameId, mapiNamedProp.GetString());

break;

default: break;

}

}

Thanks, just what I was looking for.


Thanks again for all your help.

HI Ashley,


Thank you for sharing your feedback. Please feel free to write to us if you have any further query related to the API.