Open CharlesCJ opened 7 years ago
Hi, whether this is a bug or not, please provide a complete example fot getting shared calendars ! I've seen CalendarFolder cf = (CalendarFolder) Folder.bind(service, new FolderId(WellKnownFolderName.Calendar, new Mailbox("email@domain"))); code, but it generates (at least for me) a microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: Folder doesnt exist in information store. Then a few users and I go the hard way through "Common views" and MAPI Extended Properties to get pidTagWlinkEntryId to convert to ewsId abut we then bump into that kind of issue without much help. I think it needs more explanation Thanks in advance.
I've download the source code and fix it. Java is not like C#, there has some class can't cast to, like ExtendedPropertyDefinition cannot be cast to PropertyDefinition.
Hi, CharlesCJ. I've download the source code. It Throwed Exception. Could you tell me how to fix?
Hi MaxLi001 I changed the code of type casting and type of return. (我改变了强转类型的那段源码,包括返回类型。然后打了个新的jar,修改了2.0的pom以便自己使用)
Hi, since this bug is still open - do we have some progress related to accessing shared folders in the meantime? Or is there a working example? Thanks
@CharlesCJ ,could you please share your jar, or could you please share the code how to access the shared calendars by user?
Thanks!
Hi, after change the method tryGetExtendedProperty
from protected
to public
, then it works.
Below is my code: get email list who have shared calendars with the current user.
private static List<String> getCalendarSharedEmailList(ExchangeService service) throws Exception
{
List<String> emailList = new ArrayList<String>();
FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root);
FolderView fvFolderView = new FolderView(1000);
SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Common Views");
FindFoldersResults ffoldres = service.findFolders(rfRootFolderid, sfSearchFilter, fvFolderView);
if(ffoldres.getFolders().size() == 1)
{
PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
ExtendedPropertyDefinition PidTagWlinkAddressBookEID = new ExtendedPropertyDefinition(0x6854, MapiPropertyType.Binary);
ExtendedPropertyDefinition PidTagWlinkGroupName = new ExtendedPropertyDefinition(0x6851, MapiPropertyType.String);
psPropset.add(PidTagWlinkAddressBookEID);
ItemView iv = new ItemView(1000);
iv.setPropertySet(psPropset);
iv.setTraversal(ItemTraversal.Associated);
SearchFilter cntSearch = new SearchFilter.IsNotEqualTo(PidTagWlinkGroupName, "Other Calendars");
ArrayList<Folder> folderList = ffoldres.getFolders();
Folder folder = folderList.get(0);
FindItemsResults<Item> fiResults = folder.findItems(cntSearch, iv);
for (Item itItem : fiResults.getItems())
{
Object GroupName = null;
OutParam<Object> WlinkAddressBookEID = new OutParam<Object>();
if (itItem.tryGetExtendedProperty(Object.class, PidTagWlinkAddressBookEID, WlinkAddressBookEID))
{
byte[] ssStoreID = (byte[])WlinkAddressBookEID.getParam();
int leLegDnStart = 0;
String lnLegDN = "";
for (int ssArraynum = (ssStoreID.length - 2); ssArraynum != 0; ssArraynum--)
{
if (ssStoreID[ssArraynum] == 0)
{
leLegDnStart = ssArraynum;
lnLegDN = new String(ssStoreID, leLegDnStart + 1, (ssStoreID.length - (leLegDnStart + 2)));
ssArraynum = 1;
}
}
NameResolutionCollection ncCol = service.resolveName(lnLegDN, ResolveNameSearchLocation.DirectoryOnly, false);
if (ncCol.getCount() > 0)
{
NameResolution nameResolution = ncCol.iterator().next();
emailList.add(nameResolution.getMailbox().getAddress());
}
}
}
}
return emailList;
}
@troyz Thank you for your Hint!
when I try to get shared calendars with this code :
FindItemsResults- fiResults = fFolders.getFolders().get(0).findItems(cntSearch, iv);
for (Item item : fiResults.getItems()) { try { Object wLinkAddressBookEID = null; item.tryGetProperty(extendedPropertyDefinition,(OutParam
Throws Exception: java.lang.ClassCastException: microsoft.exchange.webservices.data.property.definition.ExtendedPropertyDefinition cannot be cast to microsoft.exchange.webservices.data.property.definition.PropertyDefinition at microsoft.exchange.webservices.data.core.service.ServiceObject.tryGetProperty(ServiceObject.java:455) at microsoft.exchange.webservices.data.core.service.ServiceObject.tryGetProperty(ServiceObject.java:441)