• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1312
  • Last Modified:

How do I access the public folders through Exchange Web Services in SQL 2008 R2

Hi I am trying to implement this sample which can be downloaded here Using SQL Server Table-Valued User-defined Functions with Exchange Web Services

I have successfully built the sample and have been able to return my Contacts in my mailstore to the view in SQL.

I am trying to modify the sample to return the contacts in the public folders sub folder '\Contacts'

This function returns my contacts.
internal override StringBuilder generateSoap()
		{
			StringBuilder soapReq = new StringBuilder(200);
			soapReq.Append(ExchangeWebServiceHelper.getSoapHdr());
			soapReq.Append("  <soap:Body>");   
			soapReq.Append("    <m:FindItem Traversal=\"Shallow\">");
			soapReq.Append("      <m:ItemShape>");
			soapReq.Append("        <t:BaseShape>AllProperties</t:BaseShape>");
			soapReq.Append("      </m:ItemShape>");
			soapReq.Append("      <m:ParentFolderIds> ");
                        soapReq.Append("        <t:DistinguishedFolderId Id=\"contacts\"/> ");
			soapReq.Append("      </m:ParentFolderIds>");
			soapReq.Append("    </m:FindItem>");
			soapReq.Append("  </soap:Body>");   
			soapReq.Append("</soap:Envelope>");   
			return soapReq;
		}

Open in new window



soapReq.Append("        <t:DistinguishedFolderId Id=\"publicfoldersroot\"/> ");

Open in new window


I've attempted modifying this line to publicfoldersroot which when I try to run my query on the contacts view returns nothing I believe this is because the actual root of public folders has no items of the type contacts they are in a subfolder.




ExchangePublicFolderContacts.png
0
Lob5t3r
Asked:
Lob5t3r
  • 5
  • 2
1 Solution
 
Lob5t3rAuthor Commented:
I was able to get the folderId and changekey in another project using Hunting those elusive Public Folders using Exchange Web Services

this worked i was able to step through and confirm that the code had located the right folder with 4441 contacts inside.

FolderId: "AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwC4GC889z9fRKyshDuqQrE1AAAARzI6AAA="
ChangeKey: "AwAAABYAAAC4GC889z9fRKyshDuqQrE1AAAATaLt"

So I attempted to point the SOAP code which I am quite unfamiliar with directly at :
soapReq.Append("      <m:ParentFolderIds> ");
                        soapReq.Append("      <t:FolderId Id=\"AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwC4GC889z9fRKyshDuqQrE1AAAARzI6AAA=\" ChangeKey=\"AwAAABYAAAC4GC889z9fRKyshDuqQrE1AAAATaLt\" />");        
			soapReq.Append("      </m:ParentFolderIds>");

Open in new window



		
internal override StringBuilder generateSoap()
		{
			StringBuilder soapReq = new StringBuilder(200);
			soapReq.Append(ExchangeWebServiceHelper.getSoapHdr());
			soapReq.Append("  <soap:Body>");   
			soapReq.Append("    <m:FindItem Traversal=\"Shallow\">");
			soapReq.Append("      <m:ItemShape>");
			soapReq.Append("        <t:BaseShape>AllProperties</t:BaseShape>");
			soapReq.Append("      </m:ItemShape>");
			soapReq.Append("      <m:ParentFolderIds> ");
                        soapReq.Append("      <t:FolderId Id=\"AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwC4GC889z9fRKyshDuqQrE1AAAARzI6AAA=\" ChangeKey=\"AwAAABYAAAC4GC889z9fRKyshDuqQrE1AAAATaLt\" />");        
			soapReq.Append("      </m:ParentFolderIds>");
			soapReq.Append("    </m:FindItem>");
			soapReq.Append("  </soap:Body>");   
			soapReq.Append("</soap:Envelope>");   
			return soapReq;
		}

Open in new window


Which returned an empty table one step closer but no cigar :( lol.
0
 
LeeDerbyshireCommented:
I don't think you need the ChangeKey if you are just reading the folder items (at least, I never have).  If the change key is no longer valid (I suspect it gets updated when the folder contents change), then supplying an old one each time is not going to help much.
0
 
Lob5t3rAuthor Commented:
Hi thank you for your response I removed the changekey from the query and it still returned nothing I am wondering if the section <m:ParentFolderIds> works with <t:FolderId the way i set it up? The account I am using with the soapClient in the sample code has owner permissions on the public folders.

soapReq.Append("      <m:ParentFolderIds> ");
soapReq.Append("      <t:FolderId Id=\"AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwC4GC889z9fRKyshDuqQrE1AAAARzI6AAA=\" />");
soapReq.Append("      </m:ParentFolderIds>");

Open in new window




The sub folder Contacts has the same DefaultMessageClass of IPM.Contact as my personal contacts where ive done some tests of over 300 contacts and they return fine i'm going to test copying the entire contacts folder to my contacts to see if its a problem with quantity.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Lob5t3rAuthor Commented:
Well it looks as though it will not return more than a 1000 Contacts do I accept your answer and open a new question asking how to retrieve more than a 1000 Contacts through Exchange Web services?
0
 
Lob5t3rAuthor Commented:
By adding this line I was able to finally return the contacts from my public folders contacts folder but it seems even though i told it that MaxEntriesReturned=5000 it still only returns the first 1000 Contacts
soapReq.Append("      <m:IndexedPageItemView MaxEntriesReturned=\"5000\" BasePoint=\"Beginning\" Offset=\"0\" />");

Open in new window


0
 
LeeDerbyshireCommented:
Sorry for the delay - I live in the UK, and it's evening here.  I don't know why it only returns 1000 items, but you sometimes find strange restrictions like that when you use AllProperties (for instance, it will only return the first 1000 characters of a message body for a FindItem - to get the full message you need to do GetItem).  Try changing it to Default, and see if that helps.
0
 
Lob5t3rAuthor Commented:
Hi LeeDerbyshire I did some searching and found out about the ThrottlingPolicy which by default is set to a 1000 thank you for your assistance :)
https://blogs.msdn.com/b/exchangedev/archive/2010/03/12/throttling-policies-and-the-ewsfindcountlimit.aspx
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now