I´m developing an JAVA application which gets all contacts from Outlook via the JACOB Java Com Bridge. In Outlook there is the standard folder "Meine Kontakte" / "My Contacts" and the related sub folder "Kontakte" / "Contacts". So everything works fine and i´m getting all the contacts. But when i create another sub folder, for example "Test", the contacts inside this folder will not be shown in my JAVA application. It seems that only the contacts in the default folder will be fetched... But i need all the contacts. Does anyone know a solution?
Here is the code:
final int olFolderContacts = 10;
contact = new Vector();
ActiveXComponent ol = new ActiveXComponent("Outlook.Application");
@SuppressWarnings("unused")
Dispatch dsp = new Dispatch();
Dispatch olo = ol.getObject();
Dispatch myNamespace = Dispatch.call(olo, "GetNamespace", "MAPI")
.toDispatch();
Dispatch myFolder = Dispatch.call(myNamespace, "GetDefaultFolder",
new Integer(olFolderContacts)).toDispatch();
Dispatch items = Dispatch.get(myFolder, "Items").toDispatch();
int count = Dispatch.call(items, "Count").toInt();
for (int i = 1; i <= count; i++) {
Dispatch item;
item = Dispatch.call(items, "Item", new Integer(i)).toDispatch();
String fullName = Dispatch.get(item, "Fullname").toString();
String birthday = Dispatch.get(item, "Birthday").toString();
System.out.print(fullName);
DateFormat dateFormat = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss Z yyyy");
Calendar cal_current = Calendar.getInstance();
// Calendar birthday !!!
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);
try {
cal.setTime(sdf.parse(birthday));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@SuppressWarnings("unused")
int monthCurrent = cal_current.get(Calendar.MONTH);
@SuppressWarnings("unused")
int month = cal.get(Calendar.MONTH);
....
解决方案
Ok, here is the solution. You have to call the specific inner/sub folder.
Thanks for your help!
Dispatch innerFolder = Dispatch.call(myFolder, "Folders","Test").toDispatch();