GetSharedDefaultFolder failing

M

MichaelQuinlan

We have a very old application that uses custom templates and a shared folder
in Microsoft Outlook for managing some data. I am afraid I am not familiar at
all with this. What I am trying to do is to begin automating importing data
into the system so the users don't have to manually enter the data.

I have written a C# test application that does this

outLookApp = new Application();
NameSpace mapiNS = outLookApp.GetNamespace("MAPI");
Recipient recipient = mapiNS.CreateRecipient("* Subdivisions");
recipient.Resolve();
MAPIFolder folder = mapiNS.GetSharedDefaultFolder(recipient,
OlDefaultFolders.olFolderContacts);

The error occurs on the last line with the message "The operation failed."
The error code is -2009857777.

This leaves an Outlook process running. If I re-run the program with the old
Outlook process still running I get a different error, but I assume that is
because of the old Outlook process. I can re-create the error by using Task
Manager to end the Outlook process then re-running my test.

I would appreciate any help or advice.

Thanks,
 
S

SvenC

Hi Michael,
I have written a C# test application that does this

outLookApp = new Application();
NameSpace mapiNS = outLookApp.GetNamespace("MAPI");
Recipient recipient = mapiNS.CreateRecipient("* Subdivisions");
recipient.Resolve();
MAPIFolder folder = mapiNS.GetSharedDefaultFolder(recipient,
OlDefaultFolders.olFolderContacts);

Is this running as an Addin inproc in Outlook or as an external app?
As an external app I would assume you need mapiNS.Logon
Otherwise, are you sure that your current user has access to the
contact folder of that other mailbox?
 
M

MichaelQuinlan

This is running as an external application. I can open the folder in Outlook
without any problems.
 
S

SvenC

Hi Michael,
This is running as an external application. I can open the folder in
Outlook without any problems.

Did you try adding a Logon call on the NameSpace object?
 
M

MichaelQuinlan

Hello Sven. I appreciate your response. I added a statement like this after
the GetNamespace call:

mapiNS.Logon(null, null, true, true);

The documentation wasn't clear on what to specify for the last two
parameters so I ran the test 4 times, trying all 4 possible permutations. All
the tests got the same result, which was the same as the previous tests
without the Logon call: "The operation failed" with an ErrorCode of
-2009857777 on the GetSharedDefaultFolder call.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top