2011-03-30

No snap-ins have been registered for Windows PowerShell version 2

I was getting this message in SPPower (http://sppower.codeplex.com/), an application I am building to run powershell commands from WPF.

“No snap-ins have been registered for Windows PowerShell version 2.”

The code was basically this:

using (PowerShell ps = PowerShell.Create()) {
PSSnapInException ex = null
ps.Runspace.RunspaceConfiguration.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out ex);

Doing a search returned this helpful link:

http://blogs.msdn.com/b/pareshj/archive/2010/07/30/error-msg-no-snap-ins-have-been-registered-for-windows-powershell-version-2.aspx

This suggested it was something to do with the different OS architectures.

Then it hit me, i was developing on Vista x86, but needed it to run on Windows 2008 x64. So I went to the visual studio project, and found it was targeted to x86 platform. All i needed to do was change it to "Any CPU", so it works on both the development and target environments

2011-03-05

WD My Passport Essential SE 1TB

Well, i got a dick smith gift card for christmas, so i needed to use it up, but there is not really much at DSE that i would buy. I decided to get an external hdd for backing up stuff on my laptop while traveling.

Though i have had a little trouble with WD Green drives lately in my NAS, i decided to stick with WD.

I wanted the portable small drive, with as much storage as i could get, 1TB, and preferably with a USB 3 interface. The My Passport Essential SE 1TB http://www.wdc.com/en/products/products.aspx?id=430 gave me all of those. I would have liked to have a 7200 rpm drive, but no it didn't have one of those. I suppose it doesn't really matter as i have no usb 3 ports ... yet.

I had a look at some reviews, and people seemed to think there was a lot of bloat ware. Not a good sign. And there was a virtual cd that could not be removed. Some more searching, and i found a tool to nuke the bloat http://www.dedoimedo.com/computers/passport-vcd.html, so i was pretty much set to buy.

When i got to the shop they had 500GB Essentials and 1TB Essential SEs. I couldn't remember if the "SE" was good or bad... I took a risk and bought the SE. Luckily it turns out that the "SE" probably means second edition, and it is the evolution of the product http://www.wdc.com/en/products/external/portable/

I opened the box, and to my dismay, i saw that the cable had some port on it i had never seen. Oh no, i thought, i have got suckered into getting a non-standard proprietary piece of hardware. Turns out though, that the port is really the micro usb 3.0 standard. http://www.wdc.com/en/products/resources/drivecompatibility/

Finally when i plugged the drive in, the bloat was there, but without the virtual cd drive. A quick format, and i had a perfect drive.

2011-01-31

SharePoint 2010 List View Ribbon Missing

One thing that i find annoying with list views, is when you add any other web parts to the same page, they become an application page. This means you lose the breadcrumb view selector, and also the ribbon menu.

After playing around with this question i managed to find a solution.

Basically you trick the list view into thinking it is selected. So first, add a content editor web part to the page, then have a timer, that calls the WpClick() method, triggering the web part to be selected. Then the ribbon shows.

Perfect.

2011-01-05

Ribbon CustomAction On All Lists

For a new component I am building, I wanted to allow users to perform an action on all lists. I thought about putting it in list settings, but hey this is 2011, lets put it in the ribbon. As i knew nothing about the ribbon it was a good opportunity to study for certification.

First i had to get a basic understanding of how it all worked, these pages helped a lot. (but you have to be careful of pages relating to the beta)

http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html
http://makarandrkulkarni.blogspot.com/2010/01/sharepoint-2010-ribbon-customization_09.html
http://msmvps.com/blogs/cobrien/archive/2010/01/25/adding-ribbon-items-into-existing-tabs-groups-ribbon-customization-part-2.aspx

Adding a few simple buttons, i found out that adding a global button was not very straight forward. For starters most of the examples bind to lists, but i wanted to bind to all lists. Easy enough to change the RegistrationType to ContentType, just like you do with workflows and then the RegistrationId would be 0x01, the root content type of everything.

I tried to apply what i had learnt from the examples, to this global button, but it ended up in a mess.
Why?
Take these two list types as examples:
100 (GenericList) has a ContextualGroup "List Tools" with Tab "Items" and "List"
but
101 (DocumentLibrary) has a ContextualGroup "Library Tools" with Tabs "Documents" and "Library"
Each list type has different and unique Location paths, so you need to have a CommandUIDefinition for each location. Sure, i could duplicate the CommandUIDefinition definitions, but eventually someone would add a new list definition, with a different ribbon, and my button would not display. And duplicating xml definitions bugs me. It must be pointed out though that some people would not want an extra tab cluttering up their ribbon.

Then it hit me, i didn't have to add this button to an existing tab, i could create my own and that way the Location would be the same, globally. First i tried to create it as a ContextualGroup. Why would i do that? Well it would be cool to have a ContextualGroup called say Custom and then developers could add their custom actions to it. Unfortunately i couldn't get it to work without code. ContextualGroups need to be showed from code, which kind of makes sense (because they are contextual). So i just ended up with a simple Tab instead.

I ended up with something like this

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="{CC1A996C-A50C-430f-8666-70747F7C8D9D}"
Location="CommandUI.Ribbon"
RegistrationType="ContentType"
Rights="ManageLists"
RegistrationId="0x01">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Tabs._children">
<Tab
Id="Ribbon.Extended"
Title="Extended"
Description="Extended Settings"
Sequence="600">
<Scaling
Id="Ribbon.Extended.Scaling">
<MaxSize
Id="Ribbon.Extended.Scaling.SPC3.MaxSize"
Sequence="10"
GroupId="Ribbon.Extended.SPC3"
Size="Large" />
<Scale
Id="Ribbon.Extended.Scaling.SPC3.Scale"
Sequence="20"
GroupId="Ribbon.Extended.SPC3"
Size="Large" />
</Scaling>
<Groups Id="Ribbon.Extended.Groups">
<Group
Id="Ribbon.Extended.SPC3"
Sequence="10"
Description="SPC3 Settings"
Title="SPC3"
Template="Ribbon.Templates.ExtendedLarge">
<Controls Id="Ribbon.Extended.SPC3.Controls">
<Button
Id="Ribbon.Extended.SPC3.ShowIn"
Sequence="10"
Command="Ribbon.Extended.SPC3.ShowIn"
Image16by16="/_layouts/Com.CodePlex.SPC3/showhide16x16.png"
Image32by32="/_layouts/Com.CodePlex.SPC3/showhide32x32.png"
LabelText="Show In"
ToolTipTitle="Show In"
ToolTipDescription="Opens Show In configuration"
TemplateAlias="button1"
Alt="Show In" />
</Controls>
</Group>
</Groups>
</Tab>
</CommandUIDefinition>
<CommandUIDefinition Location="Ribbon.Templates._children">
<GroupTemplate Id="Ribbon.Templates.ExtendedLarge">
<Layout Title="Large" LayoutTitle="Large">
<Section Alignment="Top" Type="OneRow">
<Row>
<ControlRef DisplayMode="Large" TemplateAlias="button1" />
</Row>
</Section>
</Layout>
</GroupTemplate>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="Ribbon.Extended.SPC3.ShowIn"
CommandAction="~site/_layouts/Com.CodePlex.SPC3/ShowIn.aspx?List={ListId}"
/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>