Cannot create StorageItem in Outlook Add-In

白昼怎懂夜的黑 提交于 2019-12-11 03:31:36

问题


I'm trying to run this code:

this.storage =
            Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
           .GetStorage("ws_up_storage", Outlook.OlStorageIdentifierType.olIdentifyByMessageClass);

It runs perfectly well on some machines, but on others it throws this exception:

I also tried other folder names, like olFolderInbox, olFolderCalendar. I've looked at Microsoft docs for this, and it says this error is to be expected if the folder is one of the following:

  • The folder is a Microsoft Exchange public folder, an Internet Message Access Protocol (IMAP), MSN Hotmail, or a Microsoft SharePoint Foundation folder.
  • The user permission for the folder is read-only.
  • The store provider does not support hidden items.

The sad fact is, I do not know how to check which one of these is true and if it's at all possible.

How would I go about determining the cause of the problem and addressing it?


回答1:


The error 0x80040102 is MAPI_E_NO_SUPPORT, which means the store does not support hidden (associated) items.

Read the PR_MDB_PROVIDER property (DASL name http://schemas.microsoft.com/mapi/proptag/0x34140102) using PropertyAccessor.GetProperty. The returned 16 byte array will be specific for each store kind. E.g. for an Exchange store, it will be pbExchangeProviderPrimaryUserGuid (5494A1C0297F101BA58708002B2A2517). Take a look at any object in the store in question using OutlookSpy (click IMessage, IMAPIFolder, or IMsgStore) to see the PR_MDB_PROVIDER property.




回答2:


The easiest way to handle all these cases is to try to get a storage. You will need much efforts to implement all cases. The PR_MDB_PROVIDER property allows to identify the store provider, but not all cases such as user permissions for the folder and etc. You can use the try/catch block where you may check the error code - 0x80040102 (MAPI_E_NO_SUPPORT).

However, you may use any low-level property viewers (for example, a free open source tool - MFCMAPI) for exploring Extended MAPI property values. Thus, you may find all the required info about not supported scenarious.



来源:https://stackoverflow.com/questions/33282873/cannot-create-storageitem-in-outlook-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!