Archive for July, 2009

WSS and PowerShell 2

If you were one of the two people who read my last post on WSS and PowerShell I updated it a bit and it’s worth checking out the changes.

I thought this time I would just point out some of the very simple statements in PowerShell that differ from your usual C# so that you can quickly make a transition from one to another.

One of the first things any programmer might need to do in a script is conditions so here is a PowerShell condition and how it differs to c#

if ($i -eq 10)
{
    write "It's ten you know"
}

The comparison operator for equals is not "=" or "==" but a scripting style operator of -eq. So this is the first thing you’re going to have to remember.  Other operators are

-gt greater than,  -lt less than,  -ge greater than or equal to,  -ne not equal

There are more I found a simple table of them here.

When dealing with boolean responses its important to know that they are represented by $true and $false so a condition to test this would look like

if ($kidding -eq $false) {

    write "How strange" }

Now being good little programmers you’re bound to want to structure your More >

WSS3 Event Receivers

I’ve been doing some work with List Item Event Receivers and thought I’d share my experiences.

First there are a bunch of events that can be raised, I won’t list all but here are some of the good ones

ItemAdding /  ItemAddedItemUpdating / ItemUpdated

There are also specific ways of dealing with the data in each of these events, those that are “ing” events then the changes have not been applied yet so you get the change values from the AfterProperties passed in, those ending in “ed” you can grab the List Item directly as changes have already happened.

My experiences have been problematic so here is a few points that may help you when using these events.

Attachments

If you want to get hold of the attachments being added to a List, you can’t. (This may differ for doc libraries I have not inspected this).  Attachments are not on the list item as it does not exist yet and they are not in the Properties either.  Anything you want to do regarding attachments you have to do in “ed” events.

ID’s

When in the “Adding” event the one thing you have not got is the List.ID value.  If you were hoping to create entries in More >

WSS and PowerShell

The more I do with SharePoint the more and more I an finding a use for PowerShell. I am using WSS as an application platform and using lists etc as a datasource.  Providing what you want is not huge amounts of referential integrity and transactional control etc it works pretty well.

But when things go wrong, often the only way to quickly get in a fix something in a structured, repeatable and documented manner is PowerShell.  Hell and its fun too.

So as a Sharepointy person what do you need to learn to get you quickly started.

First go and install PowerShell, this is version 1 which is what I am using, version 2 will be great but is not in production yet, so try getting that on your live servers, if they let you, sack them – pre-release code on production servers pah!.

Next go and download Quest’s PowerGUI.  This comes with the fantastic script editor, that allows stepping through code and debugging, i tend to use this for all my PowerShell development, I’m used to Visual Studio so being confronted with a command shell environment can be a little daunting.

Now if you go looking on the web at powershell there are More >

WSS 3 – Site Provisioning / List Security

I’ve been having some more fun with Site Provisioning.  I have a requirement that in my Prov code I need to alter groups.  For most of my work I’ve been altering RoleAssignments in SPWebs with no trouble, however I came to do the same with a list as in an SPWeb.

Now I’m not sure if you can do security in the ONET but for my requirements I have $Resources that need concatenating together to form the group names (don’t ask).  Which it can’t do so it has to be done as a site provisioning thing.

What I noticed though is in my list, "of parent SPWEb of Parent SPWeb(RootWeb)" things where not as they were supposed to be.

The security on the list was completely wrong, as in it stated it had Unique permissions, when actually it does not, it will have when I’m finished with it, but at Site Provisioning time it should not.  Also all the groups were relating to the Site Collection level not the custom groups of the sub site it should have inherited.

It’s as if none of the list processing for fixing up the security on the list has happened, as it had done previously on SPWeb More >

WSS – ONET

Whilst messing with a product some contractor of ours did for us (SURJIT I’m talking about you).  I discovered a lovely piece of code.

The SiteDef had some SiteProvisioning code, it read an XML file to do additional processes as part of the site provisioning, rather handy in some cases.

But I did notice a few oddities.

In SiteProv he was creating lists.  Also He was copying files from the file system into Lists.  Some users just don’t have access to this part of the file system and this was exploding.

Two things about this technique,

  • 1st. You can Provision Lists in the ONET.
  • 2nd You can copy files into lists in the ONET.

The first item he should have known, so WHY do it as part of site provisioning event ?  I don’t know. Perhaps something to do with sequence, perhaps stupidity .

Second I can forgive, someone not trained in SharePoint might not know exactly what the <Module> Tag is really for.

Think of the <Module> tag in Features and SiteDefs as a kind of File copy as well as configuring what webparts go where on a page, it can copy files from the file system into a DocLibrary, but most importantly it has More >

WSS – Solutions

Just a silly one.

I’ve decided to call the WSP solution packages for WSS, Wasps.

It really appeals to me that I can send our support department a bunch of wasps.

 

Technorati Tags: ,,

WSS 3.0 – My {insert problem here} don’t work

There’s some special secret code they don’t tell you about whenever something doesn’t work.

You change a list or a web or something and nothings happens.

It’s called the Update() method.  Sshhhhh don’t tell anyone.

 

Technorati Tags: ,,