Pages

Thursday, November 15, 2007

Control SharePoint with X++ code

I have never really seen an example where you control stuff like lists on a SharePoint site from X++ without involving EP.

I have managed to "Google" my way to a couple of samples where a custom dll acts as the middleman between AX and SharePoint. But since we now have the ClrInterOp stuff in AX 4.0, you should be able to work directly with SharePoint from X++ in my opinion. And true enough you can...

Togehter with a colleague here at thy:data we have made a few scenarios for working with a different lists in SharePoint from AX.

You could for example use such a solution in the cases where a full-blown EP would be out of proportions for the customers requirements.

Here is a little teaser, which you can run on the AX 4.0 SP1 VPC image if you have a copy of that:
static void HelloSharePoint(Args _args)
{ 
Microsoft.SharePoint.SPSite spSite; 
Microsoft.SharePoint.SPWeb  spWeb; 
; 
spSite = new Microsoft.SharePoint.SPSite('http://ax401vpc');

spWeb = spSite.OpenWeb();

info (strFmt("Site name: %1", ClrInterOp::getAnyTypeForObject(spWeb.get_Title())));

spSite.Close();  
spWeb.Dispose();
}

In AX you need to add a reference to the Microsoft.SharePoint dll.

3 comments:

Doug said...

This was something I tried briefly a couple of weeks ago in order to integrate a SharePoint based product development process management system with DAX. After adding the Microsoft.SharePoint DLL to references I received the following error when first using intellisense:

Error:
Failed loading assembly Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL

I tried copying the dll to the DAX client/bin folder but still had no luck.

SørenA said...

Note that this dll is only present at the sharepoint server.

Palle Agermark said...

I haven't tried to move the dll's to the client, but that should be possible.

An easier, and better way, to go about this would be to tie your AX code to the server tier.