Hi,
I’m trying to add a task to the PST file and need to preserve last modified date on the task.
Setting date via setLastUpdate has no effect and PST created with modified date on the creation date.
Please advise.
Thanks
Hi,
I’m trying to add a task to the PST file and need to preserve last modified date on the task.
Setting date via setLastUpdate has no effect and PST created with modified date on the creation date.
Please advise.
Thanks
Please share your sample code with us. The properties should retain while adding an existing task to the PST file. Your code sample will help us analyze the issue for assisting you further.
Hi,
Here is the code:
MapiTask tmpTask = new MapiTask("Test task", "Test task body", LocalDate.now().plusDays(5).toDate(),
LocalDate.now().plusDays(10).toDate());
tmpTask.setLastUpdate(LocalDate.now().minusDays(2).toDate());
PersonalStorage pst = PersonalStorage.create("/tmp/pst1.pst", 0);
FolderInfo tasksFolder = pst.createPredefinedFolder("Tasks", StandardIpmFolder.Tasks);
tasksFolder.addMapiMessageItem(tmpTask);
pst.dispose();
Please see modified field in attached screenshot:
image.png (10.2 KB)
Could you please let us know how can we view the LastUpdate in MS Outlook? We have Outlook 2016 and can’t find the option to view this information in it. Your guidance will help us investigate the issue further at our end.
Hi,
You can choose “Detailed” in the “custom view” ribbon or create your own:
image.png (58.0 KB)
image.png (172.2 KB)
The Modified field in MS Outlook you are referring to actually represents the value of PR_LAST_MODIFICATION_TIME. The Last Update time retains as set in the message and can be verified from Outlook Spy as well. Please let us know if you have any further query in this regard.
So, what field is updated by MapiTask::setLastUpdate method ? And how can I change PR_LAST_MODIFICATION_TIME field , as I don’t see any sample how to change date property, it requires some kinf of conversion to byte array ?
Thanks
We couldn’t find the exact location in MS Outlook where the effect of Last Update could be observed. The PR_LAST_MODIFICATION_TIME field can be set using the MapiProperty as follow:
property = new MapiProperty(MapiPropertyTag.PR_LAST_MODIFICATION_TIME, convertDateTime(new DateTime(2012, 4, 11)));
message.SetProperty(property);
where
private static byte[] convertDateTime(DateTime t)
{
long filetime = t.ToFileTime();
byte[] d = new byte[8];
d[0] = (byte)(filetime & 0xFF);
d[1] = (byte)((filetime & 0xFF00) >> 8);
d[2] = (byte)((filetime & 0xFF0000) >> 16);
d[3] = (byte)((filetime & 0xFF000000) >> 24);
d[4] = (byte)((filetime & 0xFF00000000) >> 32);
d[5] = (byte)((filetime & 0xFF0000000000) >> 40);
d[6] = (byte)((filetime & 0xFF000000000000) >> 48);
d[7] = (byte)(((ulong)filetime & 0xFF00000000000000) >> 56);
return d;
}
This is not a Java code, java don’t have t.ToFileTime(), and if I’n trying to adjust java date time to get FileTime such code in Java produces PR_LAST_MODIFICATION_TIME to be 01/01/1971.
Please provide working sample in Java.
We are sorry for the confusion of missing Java with .NET. Here is the Java code that you can use for this purpose.
Sample Code
// Difference between Filetime epoch and Unix epoch (in ms).
private static final long FILETIME_EPOCH_DIFF = 11644473600000L;
// One millisecond expressed in units of 100s of nanoseconds.
private static final long FILETIME_ONE_MILLISECOND = 10 * 1000;
public static long filetimeToMillis(final long filetime) {
return (filetime / FILETIME_ONE_MILLISECOND) - FILETIME_EPOCH_DIFF;
}
public static long millisToFiletime(final long millis) {
return (millis + FILETIME_EPOCH_DIFF) * FILETIME_ONE_MILLISECOND;
}
public static Date getDate(int year, int month, int date) {
java.util.Calendar c = java.util.Calendar.getInstance();
c.set(java.util.Calendar.YEAR, year);
// Month value is 0-based. e.g., 0 for January.
c.set(java.util.Calendar.MONTH, month - 1);
c.set(java.util.Calendar.DAY_OF_MONTH, date);
c.set(java.util.Calendar.MILLISECOND, 0);
c.set(java.util.Calendar.SECOND, 0);
c.set(java.util.Calendar.MINUTE, 0);
c.set(java.util.Calendar.HOUR_OF_DAY, 0);
return c.getTime();
}
private static byte[] convertDateTime(Date t)
{
long filetime = millisToFiletime(t.getTime());
byte[] d = new byte[8];
d[0] = (byte)(filetime & 0xFF);
d[1] = (byte)((filetime & 0xFF00) >> 8);
d[2] = (byte)((filetime & 0xFF0000) >> 16);
d[3] = (byte)((filetime & 0xFF000000) >> 24);
d[4] = (byte)((filetime & 0xFF00000000L) >> 32);
d[5] = (byte)((filetime & 0xFF0000000000L) >> 40);
d[6] = (byte)((filetime & 0xFF000000000000L) >> 48);
d[7] = (byte)((filetime & 0xFF00000000000000L) >> 56);
return d;
}
Usage
MapiProperty property = new MapiProperty(MapiPropertyTag.PR_LAST_MODIFICATION_TIME,
convertDateTime(getDate(2012, 4, 11)));
Great, it’s worked !!!