home  |  articles  |  quotes   ::   website  |  profile

SharePoint

RPoint - Why Ruby? What about XML?

I wanted to do a quick post on why I chose Ruby for RPoint. I talked about this a little in the first post but just looking at the examples I’ve given so far, one could make the argument that rather than creating these scripts in ruby, you could just create a simple XML document that defines your structure, templates, etc.

This is very true - and in fact I have written tools like this in the past. But here’s the problem I’ve encountered with XML. You end up trying to build a programming language out of XML. That’s basically where CAML has ended up. And I don’t know a single person who actually enjoys looking at, much less creating, CAML.

Here’s what I like about the ruby approach. It let’s you write something like this:

site_names = ["Site One", "Site Two", "Site Three"]
at "http://localhost" do
  site_names.each do |name|
    create_web name, TeamSite
  end
end

Just the simple addition of an array of site names is something that would be hard to do in XML. What if you wanted to pull your information from a database? Or a file system? Or an Excel spreadsheet? For any of those you would have to write more logic into your XML mini-language - constructs like looping, conditionals, some mechanism to handle plug-ins for additional logic, etc. By leveraging an actual programming language, we get all of that for free.

Want to create 50 test sites? Here you go.

at "http://localhost" do
  50.times do |i|
    create_web "Site #{i}", BlankSite
  end
end

’nuff said.

RPoint
Ruby
SharePoint

Comments (4)

Permalink

RPoint - Hopes and Dreams

Yesterday I posted about RPoint for the first time and I showed you a simple script to create a site structure. All of that code is working today. I wanted to keep the example simple and show you something that was actually functional.

Today I want to dream a little. Here are a few scripts I want RPoint to be able to support.

Creating a List Template

This script would create a list template.

class Milestones
  include ListTemplateMixin

  name "Milestones"
  description "A Simple Milestone List"

  column "Milestone", Text, :is_title => true, :required => true
  column "Description", RichText
  column "Date", Date, :required => true, :default => :today

  view "All Milestones" do
    show_columns "Milestone", "Date"
  end

  view "Overdue Milestones" do
    show_columns "Milestone", "Date"
    where :date => less_than(:today)
    order_by :date => :descending
  end
end

Once you had defined your template, you could use it in a few different ways. First, you could use it in a site creation script:

at "http://localhost" do
  create_list "My Milestones", Milestones
end

Second, and possibly cooler, you could generate a list definition:

>ir generate.rb list_definition --source MilestoneTemplate.rb

Migrations

Migrations in Rails is a great pre-defined structure for handling your database schema and changes to it over time. It may not be anything too ground-breaking on its own, but it enforces a discipline when it comes to managing your database. You are encouraged to think about situations where you want to change your database but data already exists. You can write scripts to migrate existing data to your new structure and it’s all managed within source control as an ordered list of steps to execute.

I want to be able to do something similar with RPoint.

# first migration - create my site collection
class CreateSiteMigration
  at :webapp => "http://localhost" do
    create_site "My Site", TeamSite
  end
end

# second migration - add a list and add a lookup to that list on an existing list
class AddIssuesMigration
  at "http://localhost/sites/mysite" do
    create_list "Issues", Issues
    update_list "Tasks" do
      add_column "Related Issue", Lookup("Issues", :field => :title)
    end
  end
end

Okay - that’s enough dreaming for now. Just incase anyone missed the intro THIS CODE DOES NOT WORK. It is completely imaginary. I am hoping that something along these lines will become reality. And I hope that you will agree that this would be a much nicer way to create SharePoint solutions than slogging through hundreds of lines of XML.

RPoint
Ruby
SharePoint

Comments (0)

Permalink

RPoint - a DSL for SharePoint

A few days back I talked about how the release of IronRuby would be great for SharePoint scripting. In my opinion, what makes Ruby such a powerful language is that it is great for creating domain specific languages (DSLs). I’m going to keep this post short so I won’t go into what DSLs are or examples of them. If you want to find out more info, look at some other ruby libraries such as rspec, rake, and datamapper.

I think that SharePoint is in dire need of better tools to facilitate solution development, deployment, and maintenance. It is simply too difficult to build a site in one environment and then deploy it in production. Sure you can do backup and restore, but what about when you want to make some upgrades?

Anyway, this weekend I started working on an IronRuby-based DSL for SharePoint scripting. I’m calling it RPoint for now (until I think of something sexier!). Now, this is very very very early in development and I am sure things aren’t set up today as nicely as they should be long term, but I’ve been really excited by the progress and the possibilities.

RPoint will allow you to write code like this to create SharePoint sites:

# create a new subweb beneath an existing site
at "http://localhost" do
  create_web "New Web", TeamSite
end

# create a new site collection and website structure
at :webapp => "http://localhost" do
  create_site "New Site Collection", BlankSite, "domain\\user" do
    inside root_web do

      # create our site structure
      create_web "Child Web", TeamSite
      create_web "Another Child", BlankSite do
        create_web "Private Site", TeamSite, :inherit_permissions => false
      end

      # create a few lists
      create_list "Documents", DocumentLibrary
      create_list "Announcements", Announcements

    end
  end
end

I think that’s pretty cool. Beyond simply creating sites, RPoint will allow you to create lists, views and probably upload resources like images and documents.

My goals for RPoint are to be able to do the following:

  • Easily write scripts to create site structures and lists
  • Rails-like “Migrations” for applying changes to existing sites
  • Custom site template and list definitions in ruby as opposed to XML
  • Ability to run template/list definitions against a live site or generate schema.xml/onet.xml files for production deployment
  • Support web-services automation as well as object model automation (this will be tough)

SharePoint is a huge product. The code-base is enormous and the aspirations for RPoint are lofty. I would greatly appreciate any assistance. The more hands there are to help, the sooner we will have a tool to make SharePoint development a little easier.

To get RPoint in its current form, you can download it from GitHub.

RPoint
Ruby
SharePoint

Comments (2)

Permalink

IronRuby - a SharePoint Developer’s Best Friend

I wrote a while back about SharePoint scripting with IronPython. Well today’s announcement of the first binary release of IronRuby got me pretty darn excited. I really like Python, but I LOVE Ruby. I’ve been waiting for IronRuby to catch up to IronPython for quite a while and it looks like they’re getting close.

Here’s a quick guide to getting up and running with IronRuby and SharePoint.

Installation:

  1. First, download the IronRuby release from Rubyforge.
  2. Next, copy the ironruby folder you extract to your Program Files (put it wherever you like - that’s where I put mine).
  3. Update your system’s PATH environment variable to contain the path to the ironruby\bin folder.  So if you placed it in your Program Files, you would add this to your PATH: c:\program files\ironruby\bin

Creating a Script:

Next you’ll want to create a new text file called print_sites.rb. I recommend the e text editor by the way - great tool.  Add the following lines to your file:

require 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL'
require 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL'

Uri = System::Uri
SPSite = Microsoft::SharePoint::SPSite
SPWebApplication = Microsoft::SharePoint::Administration::SPWebApplication

Okay - what does that do? Well the first two lines are like adding a reference to a standard Visual Studio project. They tell IronRuby that we need to reference (require) the System and Microsoft.SharePoint assemblies. The next three lines are for convenience. They set up aliases to the System.Uri class and two SharePoint classes. In our ruby code, now we can just use Uri, SPSite, etc instead of having to type out the fully qualified path.

Next, let’s add some ruby code to enumerate all sites in a web application.

webapp = SPWebApplication.Lookup(Uri.new("http://localhost"))
webapp.Sites.each do |site|
  puts site.Url
end

(hmm, looks like I don’t actually need the SPSite alias after all)

Now, save your file. You can execute it like this:

> ir print_sites.rb

If everything is set up right, you should see the URL for each site collection be printed to the screen.

There you go. Have fun.

Ruby
SharePoint

Comments (1)

Permalink

sp.py - SharePoint Scripting with Python

I wrote a small introduction to SharePoint scripting with Python a while back and this weekend I didn’t have anything better to do (well actually I did, but I’m an addict - what can I say) so I decided to expand on it.  I’ve started putting together a small Python library for working with SharePoint using IronPython.  It’s called - amazingly - sp.py.

So far the library if pretty small - although it does include a nice little module for workign with stsadm commands.  I’ll be adding to it as necessary.  I’ve decided that although adding custom stsadm extensions is nice and does fit into the “way to do things in SharePoint”, it’s just too much overhead when you want to do something simple.  So at this point when things come up that need automation, I’ll be adding new sp.py scripts.

In addition to the sp.py library I’ve added three scripts:

So where can you get this awesomeness?  Well, actually you can get it on github.  Github???  You mean that totally web 2.0 site for hosting Git repositories?  Yeah - that’s the place.  If you’re wondering why I’m using git for source control, well I guess Subversion just wasn’t “edge” enough anymore.  Git’s actually pretty cool - and if you need to use Windows you can download a Windows version here.

At some point I’ll figure out how to post it as a zip or something instead of a tarball.  But until that point, you can grab the tarball here.

Office System
Python
SharePoint
Software Development

Comments (0)

Permalink

Introducing the SharePoint Knowledge Base

I’ve had this project in the works for a while now and it’s time to open it up to the world. The SharePoint Knowledge Base is a simple wiki site I created to capture some best practices, how-tos, tips and tricks, etc. While I think that blogs are great tools to communicate this sort of information, I’m not satisfied with the experience of searching for a specific issue or problem. Often times I find myself sifting through numerous blog posts - sometimes with conflicting information - left wondering which author knows his or her stuff.

The intent of the SharePoint Knowledge Base is to provide a wikipedia-like site dedicated to capturing community-driven expert content around SharePoint.

Today, there is not a lot of content. That’s where you come in. We all come across things every day that the rest of the community can benefit from. Why not take a minute and jot down your notes here in the SharePoint KB? Not only for your own future reference, but for the benefit of others as well.

There is no registration required to create or edit content. Until we start to have problems this site will remain completely open for anyone to edit.

So please, if you have something to contribute I would encourage you to post it here.  We can all benefit from a better way to store and update SharePoint-related information.  There’s so much of it out there but it’s so hard to sift through.  I hope that together we can start to chip away at this problem.

Office System
SharePoint

Comments (2)

Permalink

SharePoint 3.0 Built-In Fields

I just came across this amazing resource of field types and their XML schema.

 http://www.johnholliday.net/download/fieldswss.htm

Office System
Reference
SharePoint

Comments (0)

Permalink

Oops. I deleted the SSP Admin Site Collection…

Hey - we’ve all made mistakes.  We all know that “oh sh**” moment right after we realize what we’ve done.  Often times this occurs right after we click a friendly “Are you sure??” dialog.  Of course I’m sure - if I wasn’t sure I wouldn’t have chosen to do it in the first place!  Stupid computer.

Anyway, I recently had a situation where someone (honestly, in this case it wasn’t me) accidentally deleted the Site Collection for the SSP admin site (/ssp/admin).  Since this was for a SharePoint farm in production I really didn’t want to have to re-create the entire SSP but I couldn’t figure out how to just re-create the site collection itself.  I figured there had to be a site template for the site but since it didn’t show up in the Create Site Collection UI I went and looked on disk.  Sure enough, a site template exists for the SSP Admin site.  It’s called OSRV.

So to create a new SSP admin site, run this command line.

stsadm.exe -o createsite -url http://<server>:<ssp_port>/ssp/admin -owneremail <email address> -ownerlogin <account> -sitetemplate OSRV#0 -title "Shared Services Administration: <your ssp name>"

This might take a little while to complete, but it does eventually finish.

Next you need to edit the SSP to point to the recreated site.

stsadm.exe -o editssp -title "<your ssp name>" -sspadminsite http://<server>:<ssp_port>/ssp/admin

That’s it.  You should be back up and running.

2007 Office
Office System
SharePoint

Comments (0)

Permalink

SharePoint? Meet Python

Ever have a need to quickly script some administrative task relating to SharePoint? Ever wish there was more you could do with STSADM? Ever wish you had an interactive console for exploring the object model and testing various methods or properties? Well Iron Python is your answer. In this short article I’ll show you how to get up and running with Iron Python and SharePoint. I’ll also show you a few scripts that will give you some insight into the potential power of this extremely useful combination. Continue Reading »

2007 Office
Articles
Python
SharePoint

Comments (6)

Permalink

Site Templates

I hate searching for this stuff every time I need it.  So here is a list of SharePoint site templates and their friendly names.

Friendly Name Template
Team Site STS#0
Blank Site STS#1
Document Workspace STS#2
Wiki Site WIKI#0
Blog BLOG#0
Basic Meeting Workspace MPS#0
Blank Meeting Workspace MPS#1
Decision Meeting Workspace MPS#2
Social Meeting Workspace MPS#3
Multipage Meeting Workspace MPS#4
Document Center BDR#0
Records Center OFFILE#1
Personalization Site SPSMSITE#0
Site Directory SPSITES#0
Report Center SPREPORTCENTER#0
Search Center with Tabs SRCHCEN#0
Search Center SRCHCENTERLITE#0
Publishing Site CMSPUBLISHING#0
Publishing Site with Workflow BLANKINTERNET#2
News Site SPSNHOME#0

Office System
Reference
SharePoint

Comments (1)

Permalink