One of the pain points in having IronRuby access SharePoint classes is that you'll have to help IronRuby find the appropriate assemblies. IronRuby (at least with the 0.9.0 version) has an IronRuby folder underneath the lib folder in its main directory tree which you can populate with a "shortcut". To do this, create a file named Microsoft.SharePoint.rb in this IronRuby folder and type in the following:
-
require 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.AdministrationOperation, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.Diagnostics, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.Library, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.WorkflowActions, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
-
require 'Microsoft.SharePoint.Workflows, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
Once you've done this, importing the SharePoint assemblies while you're inside the ir.exe console is as simple as the command:
require 'Microsoft.SharePoint'
And you may now do things like:
site = Microsoft::SharePoint::SPSite.new 'http://myspserver/sites/mysite'
web = site.OpenWeb
mylist = web.Lists.get_Item 'My Sample List'
You can even do reflection on the SharePoint objects, e.g. to display all methods or messages understood by an instance of the SPSite class:
site.methods
Have fun!
Posted
09-26-2009 8:00 AM
by
cruizer