SharePoint 2010 PowerShell enable/disable feature for all site collections

Category : Powershell, sharepoint

A lot of enterprise portals build multiple site collections within the web application of a SharePoint farm. This is a scalable architecture that allows for separation of databases, site collection administration differentiation and a host of other benefits from the SharePoint administration point of view. This architecture also has some downsides including global navigation and different settings on the multiple site collections. If this is your architecture of choice, enabling features across all site collections is also an issue. What if you buy a third party product and need to enable the feature globally? What if you build a reusable component? Every time I need to do this I find myself Googling Binging Googling the answer to this question.

Below are helpful commands that wrap the Enable and Disable features in the get all site collections for a web application. Also, notice the “whatif” command for testing. This is a very valuable functionality of PowerShell that I highly suggest using before running the commands.

Enable Feature Testing

Get-SPWebApplication “<WebApplicationURL>” | Get-SPSite -Limit ALL |
ForEach-Object {Enable-SPFeature “MyFeatureID” -Url $_.Url -WhatIf}


Enable Feature without Confirmation

Get-SPWebApplication “<WebApplicationURL>” | Get-SPSite -Limit ALL |
ForEach-Object {Enable-SPFeature “MyFeatureID” -Url $_.Url -confirm:$false}’


Disable Feature Testing

Get-SPWebApplication “<WebApplicationURL>” | Get-SPSite -Limit ALL |
ForEach-Object {Disable-SPFeature “MyFeatureID” -Url $_.Url -WhatIf}


Disable Feature without Confirmation

Get-SPWebApplication “<WebApplicationURL>” | Get-SPSite -Limit ALL |
ForEach-Object {Disable-SPFeature “MyFeatureID” -Url $_.Url -confirm:$false}



Hope this helps someone else. Also, sorry for the forum I originally got this answer from. I’d give you credit if I remembered where it was. I just had this in my notes and decided to put it on my blog in case it helps others.

SharePointShout launched

1

Category : SharePointShout, sharepoint

I just released http://www.sharepointshout.com. This is a Digg style website where users can submit and promote/demote SharePoint related links. The project is based off the Kigg Framework on CodePlex and was built using ASP.Net MVC and the Entity Framework.

SharePoint Edit Page on List Forms

Category : sharepoint

Usually editing a page in SharePoint is as easy as choosing Edit Page from the Site Actions menu. However, list forms don’t have this capability. Here is a quick tip on how you can a SharePoint page even when the Site Actions menu doesn’t contain the Edit Page option.

Just insert “&ToolPaneView=2″ at the end of the url.

So, if your url is: http://sharepoint/Lists/Announcements/EditForm.aspx?ID=1&Source=http%3A%2F%2Fwin2008r2%2FLists%2FRoster%2FAllItems%2Easpx

then, all you have to do is change the url to: http://sharepoint/Lists/Announcements/EditForm.aspx?ID=1&Source=http%3A%2F%2Fwin2008r2%2FLists%2FRoster%2FAllItems%2Easpx&ToolPaneView=2

This little tip becomes really nice on the forms we use to edit list items. This is an oldy, but a good – but, it came up recently with one of my clients and I thought I’d write this for him – you know who you are.

SharePoint compare differences in Word Documents

1

Category : sharepoint

Recently, a co-worker of mine asked me if SharePoint had a diff tool like Source Safe. In fact, he phrased the question as “I am sure SharePoint has this functionality, but I just wanted to check”. I thought about it for a second and realized that SharePoint should have this functionality, especially with Word Documents. So, I started to do a little research.

In Word there is a comparison tool that allows a user to compare two Word documents. This tool is great. I no longer have to require people to keep track changes on when I ask them to review my documents.

The issue I immediately saw with this tool is that you are required to have two files to compare. However, we wanted to compare two versions in SharePoint. What I concluded is that if you open up a Word document, from SharePoint, from a library with versioning turned on, that dropdown changes and looks like this:

So, SharePoint does have a Word diff/comparison tool. Actually, Word has the tool, it just works very nicely with SharePoint.

SharePoint Dynamics CRM Integration

Category : Dynamics CRM, sharepoint

I recently ventured into Dynamics CRM integration with SharePoint and was surprised with all the different ways to integrate the products. After playing around with all the different capabilities I came to some conclusions that I thought I would shared.

Dynamics CRM has a very nice UI and seems to be very customizable. However, out of the box it is setup for very specific functionality. Thus, turning it into a true portal seems like it will take some work. Microsoft has created some “accelerators” to help with these customizations: http://crmaccelerators.codeplex.com/.

However, before thinking about integration we have to take a step back and think about who is going to be accessing the systems. Is the CRM system going to be a “portal”? Or, is it going to be used by high end, customer/contact relationship individuals? Are there people in the organization who need to see some of the CRM data, but not other parts? Is the out-of-the-box SharePoint functionality important to your end users?

If we make CRM the “portal” and then want to incorporate SharePoint functionality into it, most people seem to use iFrames to do this. I am not a big fan of iFrames, so I don’t see that as the best possible solution. I do see that as a “one off” solution to incorporate a little more functionality into CRM, but I don’t see it as a strategy for an extensible portal structure.

Thus, I turned the other way in my thinking and decided to incorporate CRM data into SharePoint. The thought here is to let your contact/customer relationship people work in the CRM system, but expose important data from that system into SharePoint. Thus, SharePoint is still the place the majority of your users go to in order to collaborate and view business lines of data. CRM is just the management system for you contacts. This seems to be a good separation of functionality to what can be a fuzzy line because of the amount of flexibility in both products.

Creating the CRM Dashboard in SharePoint

For this blog I am dealing with Dynamics CRM 4.0 on-premise and Enterprise MOSS 2007. These techniques will only work with the On-Premise version of Dynamics CRM because the Online version does not give access to the database.

The CRM Dashboard shows CRM data to the end user through charts, graphs and bdc lists. This data is in a read-only format in SharePoint. However, the BDC lists have custom “actions” which allows the data to be edited in Dynamics CRM by opening up CRM windows to the specific entity needing editing.

In order to create this dashboard the first step is to create the BDC definitions for SharePoint. The BDC  definitions define how to interact with the Database for Dynamics CRM. I created my definitions using BDC meta man and I was quite impressed with the structure of the database Dynamics CRM creates. This makes it a lot easier to work with the BDC. However, if you don’t have access to BDC meta man you have other choices:

  1. Use the Microsoft BDC Definition Editor found in the SharePoint SDK http://www.microsoft.com/downloads/details.aspx?familyid=6d94e307-67d9-41ac-b2d6-0074d6286fa9&displaylang=en
  2. Use the Enterprise Search Accelerator for Dynamics CRM http://crmaccelerators.codeplex.com/releases/view/21449

The Microsoft BDC Definition Editor is perfectly fine for creating simple BDC files. However, I prefer BDC meta man (which is a pay for product) for creating more robust, complicated BDC files. The Enterprise Search Accelerator for Dynamics CRM is a great place to get started. They actually created a pretty comprehensive BDC file that hooks into Dynamics CRM 4.0. I completed 90% of my Dashboard with their BDC. I just used BDC meta man to create some relationships and entities they didn’t include. I “highly” recommend people start with this accellerator when integrating SharePoint and Dynamics CRM.

So, step number 1 in creating a Dynamics CRM Dashboard in SharePoint is to use the search accelerator BDC files.

The other good thing about the search accelerator is that they show you how to setup your bdc files for search (if you don’t know how to do that) and they show you how to utilize the BDC WebParts to create connections. Thus, after you are finished with their walkthrough (which is very well written and easy to follow), you should have something like this:

I crossed out any personal information in the image so people don’t spam me :)

Notice that you can now start showing your CRM data in SharePoint, through the BDC, and you can connect your relationships together just like they are connected in Dynamics CRM. Also, through the use of custom actions, we get menus for opening/editing the entities in CRM popups:

After you have the BDC hooked up and some BDC webparts on your screen through the search accelerator for CRM, you can see the process of showing CRM data through normal BDC techniques in SharePoint. At this point, I went ahead and edited the BDC file from the search accelerator with BDC meta man to add in more entities, relationships and I even added some filters.

Step number 2 in my process for creating this Dashboard was using Dundas Charts for SharePoint to show some charts. http://www.dundas.com/Components/Products/Chart/sharepoint/index.aspx. This is a pay product, but it is relatively inexpensive and has many uses in a SharePoint environment. SharePoint 2010 does have some charting capabilities, but if you are on SharePoint 2007 you need a product like this. The Dundas Charts can hook into the BDC to use the same exact data that we previously used for our webparts. Also, the Dundas Charts allow you to use simple SQL Queries to access the data. I used SQL Queries so that I could do some grouping and counts to get my data. But, either way will work.

So, that’s basically it. Without any real development I had a pretty good dashboard to expose some of my CRM data into my SharePoint portal. I just used 2 tools to get me started:

  1. CRM Accelerators from SharePoint to get me started on my BDC
  2. Dundas Charts for my graphical representations of my data

I know there are lots of other techniques for integrating these two products together. But, I believe this is the best technique in order to let the products do what they are meant to do. CRM is meant for certain people in the organization to maintain those relationships. It is hard to control if you let an entire organization into your CRM system. SharePoint is meant for portal and collaboration functionality. In addition, SharePoint is a great platform for Business Intelligence. Reporting your CRM data in SharePoint for you organization is a logical choice.

HiSoftware Accessibility Foundation Module

1

Category : Accessibility, sharepoint

First look at the Accessibility Foundation Module from HiSoftware:

The other day I wrote a post that HiSoftware announced their Accessibility Foundation Module. Shortly after that the CEO from HiSoftware contacted me and asked if I would like a walkthrough of the module. Of course, I jumped at the opportunity.

The Accessibility Foundation Module is an add-on to HiSoftware’s Compliance Sheriff. Compliance Sheriff is a tool that checks the accessibility of a SharePoint site. Since SharePoint is a Content Management tool, many people can enter content. But, that content isn’t always accessible. Among other things, Compliance Sheriff checks the accessibility of content being add by end-users into a SharePoint site. It can do this with custom workflows and reports.

The Accessibility Foundation Module is an add-on ontop of Compliance Sheriff. This module uses the same idea of the Accessibility Toolkit from HiSoftware (custom master pages, css sheets and control adapters). The Accessibility Foundation Module does look like a final product that can be installed onto a SharePoint site. It uses a feature to install (very nice compared to the installation of the Accessibility Toolkit). It also uses the “common” master page/look and feel for SharePoint (the Accessibility Toolkit only worked with the external/extra master pages).  Also, it takes care of a lot of the common problems with SharePoint accessibility.

One of the features I really liked was the ARIA support (http://www.w3.org/WAI/intro/aria).

The pricing model seems to be a CAL/server based license. It looks like this can get pretty expensive for large implementations. Truthfully, I didn’t get a full understanding of the pricing model based on the conversation (I need to talk more to them about that). But, regardless of the price, I think accessibility is worth it (especially in government space). So, all government agencies working with SharePoint 2007 should look into this when pricing out their implementations.

I haven’t had a chance to use this tool yet (I only got the walkthrough). So, once I get my hands on it I will be able to write another review. Until then, I’m going to encourage my clients to look into this because it “seems” to be far and away the best implementation I’ve seen for accessibility and SharePoint.

For anyone who is on the SharePoint 2010 bandwagon already, I did ask them about it. HiSoftware says that SharePoint 2010 isn’t as accessible as Microsoft wants us to think. I’d like to get a few instances from them, but that was very interesting to hear. So, HiSoftware is making this for SharePoint 2010 too. After I do a full assessment of SharePoint 2010 and accessibility I will be able to see whether the HiSoftware price is justified for this version.

HiSoftware announces Accessibility Foundation Module

1

Category : Accessibility, sharepoint

HiSoftware just announced their AFM (Accessibility Foundation Module). http://www.hisoftware.com/products/CS_AFM.html.

“The optional Accessibility Foundation Module (AFM) provides users with a set of tools to create an accessible platform/framework for a SharePoint portal or intranet site. AFM is integrated into the Compliance Sheriff offering to provide a more complete and easy-to-deploy method of addressing SharePoint framework accessibility. The most significant advantage of AFM is the enterprise-friendly installation method that allows a SharePoint Server Administrator to easily apply a master configuration to multiple SharePoint Applications.”

I was never really a fan of the “completeness” of HiSoftwares Accessibility Kit for SharePoint. The ideas were good, but the implementation seemed incomplete to me. I did use their ideas and extend that kit for accessible SharePoint projects. But, could never use it out-of-the-box and the amount of work involved was always very high. Hopefully this new Module is more of an out-of-the-box approach to accessibility (I’d rather pay vs build for this).

I don’t know too much about the details of this Kit yet, but as soon as I get my hands on it I will post my thoughts.

Approve all items button in a SharePoint View

2

Category : sharepoint, webpart

Situation – You’ve been tasked with building a mechanism for an approver to approve all the pending items in a SharePoint list. 

Implementation – Single Approve All button WebPart that only shows for approvers. This WebPart can be shown on one of the view pages of the list

1. Place the WebPart on a View of the List

  • Go to the list
  • Click Edit Page
  • Add the WebPart in the top zone

2. Loop through the items in the current list and set the approve flag

  • This is in the btnApprove_click event handler below
  • This checks if the item is in pending status and approves the item
  • This will cancel approval workflows currently running on the item

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow; 

namespace ApproveAll
{
[Guid("a73bd0c2-a842-4c37-8021-447f550428b5")]
public class ApproveAll : Microsoft.SharePoint.WebPartPages.WebPart
{
private bool _error = false; 

public ApproveAll()
{
this.ExportMode = WebPartExportMode.All;
} 

///
/// Create all your controls here for rendering.
/// Try to avoid using the RenderWebPart() method.
///
protected override void CreateChildControls()
{
if (!_error)
{
try
{
base.CreateChildControls(); 

//get the list
SPList list = SPContext.Current.List; 

//Show the approve button for users with approve permissions to this list
if (list.DoesUserHavePermissions(SPBasePermissions.ApproveItems))
{
Button btnApprove = new Button();
btnApprove.Text = "Approve All";
btnApprove.CssClass = "ApproveAllButton";
btnApprove.Click += new EventHandler(btnApprove_Click);
this.Controls.Add(btnApprove);
}
}
catch (Exception ex)
{
HandleException(ex);
}
}
} 

///
/// Loops through all items in the current list and approves them.
///
///
///
void btnApprove_Click(object sender, EventArgs e)
{
//get the list
SPList list = SPContext.Current.List; 

//approve all items
foreach (SPListItem item in list.Items)
{
if (item.Level == SPFileLevel.Published)
continue; 

SPFile sourceFile = item.File;
if (sourceFile != null)
{
//Update files
if (sourceFile.Item.ModerationInformation.Status == SPModerationStatusType.Pending)
{
CancelWorkflows(list, item);
sourceFile.Approve("Bulk Approval by" + SPContext.Current.Web.CurrentUser.LoginName);
}
}
else
{
//Update simple list items
if (item.ModerationInformation.Status == SPModerationStatusType.Pending)
{
CancelWorkflows(list, item);
item.ModerationInformation.Status = SPModerationStatusType.Approved;
item.ModerationInformation.Comment = "Bulk Approval by" + SPContext.Current.Web.CurrentUser.LoginName;
item.Update();
}
}
}
} 

private static void CancelWorkflows(SPList list, SPListItem item)
{
if (list.DefaultContentApprovalWorkflowId != Guid.Empty)
{
SPSecurity.RunWithElevatedPrivileges(delegate{
foreach (SPWorkflow workflow in item.Workflows)
{
if (workflow.ParentAssociation.Id == list.DefaultContentApprovalWorkflowId)
SPWorkflowManager.CancelWorkflow(workflow);
}
});
}
} 

///
/// Ensures that the CreateChildControls() is called before events.
/// Use CreateChildControls() to create your controls.
///
///
protected override void OnLoad(EventArgs e)
{
if (!_error)
{
try
{
base.OnLoad(e);
this.EnsureChildControls();
}
catch (Exception ex)
{
HandleException(ex);
}
}
} 

///
/// Clear all child controls and add an error message for display.
///
///
private void HandleException(Exception ex)
{
this._error = true;
this.Controls.Clear();
this.Controls.Add(new LiteralControl(ex.Message));
}
}
} 

Sorry for the lack of proper indentation in the code. The blog did it :)

Now, build and deploy the custom WebPart. Then, go to any view in your List. Edit the page and drop the custom Approve All WebPart in the WebZone (right above the list view). 

*Just remember: this only works if you put the WebPart on a view “in the list” because it infers the list object from the current context. Also, if you want this on multiple views for the list, you must place it on all the views. 

Happy hacking!

MOSS Project Tasks Gantt Chart size issue in Firefox

1

Category : sharepoint

When you use a Gantt Chart web part, from the project tasks list in MOSS, you get a scroll bar at the bottom so that it fits in the screen (in Internet Explorer). This is done with a div tag and an overflow style of auto in the ms-ganttDiv of the core.css file in SharePoint.

gantt

However, in any other browser (other than IE), you don’t get the scroll bar. Instead, the Gantt Chart is set to the full width and your browser page becomes very wide.

This happens because SharePoint uses a different style for browsers other than IE. For other browsers ms-ganttDiv is replaced with ms-ganttDivNonIE. So, using my trusty developer toolbar in IE and Firebug in Firefox, I decided to check out these two styles.

The difference between the two is the “position” property. In IE, the position is set to absolute. In the other browsers, the position is set to inherit.

So, I decided to switch the position to absolute in Firefox to see what happens. And, of course, it looked horrible (I knew the SharePoint developers did this for a reason).  It makes the Gantt Chart overflow over the size of the webpart.

ganttFirefox

I tried playing around with different css settings to see if I could fix this. But, I think I found the same thing the SharePoint developers found, it is very hard to fix this issue in non-IE browsers (no wonder they hacked this up).

Thus, my conclusion is to make this a fix width Gantt Chart. All I did was set my WebPart to fixed width (instead of 100% height). Then I added a css style to my site to set the width of the ms-ganttDivNotIE.

.ms-ganttDivNotIE{ width:800px; }

Note: making the WebPart width the same size as the .ms-ganttDivNotIE is important. If you don’t do this, the user could see space between the end of the Gantt Chart and the border of the WebPart.

It’s not the perfect solution, but it makes the site act consistent in Firefox and IE (that was my requirement).

Inheriting Themes for SharePoint publishing sites

2

Category : sharepoint

SharePoint themes do not inherit when creating a site/sub-site structure. Try it, set a theme to the root site in your site collection, set the theme to something other than the default, then create a sub-site under that site. Notice that this sub-site automatically gets set to the default theme again. Now your users have a different design experience as they navigate through your site. That might be ok if you are creating different team sites, but it doesn’t create a cohesive experience when building a portal structure. Of course, you can always set the theme every time you create a sub-site, but wouldn’t it be nice if you didn’t have to do that (especially if you have an environment where less experienced SharePoint administrators are adding sub-sites).

I’ve never  been a big fan of themes in the past. I usually create my own css and put it in the layouts folder and access it in the master page. But, that is only when I have time to customize my site. Every once in a while I have to put a quick SharePoint site together using out-of-the-box functionality and I need to use the out-of-the-box themes to give a distinct look to a particular site collection.

The following technique shows a way to gain that theme inheritance behavior for SharePoint publishing sites.

Note: The following directions are for MOSS publishing sites because you can set the alternate css in MOSS through the interface. In addition, you must make sure that all of your sub-sites are set to inherit the alternate css.  And lastly, you must have the publishing features turned on. Of course, all these settings are set by default when you use one of the publishing templates to create your site and sub-sites. It works really nice with the Collaboration Portal template for the site collection and the Publishing Site templates for the sub-sites.

  • Set the theme you want to on the home page of your site collection (Site Settings – Look and Feel – Site Theme – Choose a theme)
  • Go to the site collection home page and view the source (right-click on the page in your browser and choose view source)
  • Do a search for the word _themes and copy the link from the href tag. For example: a tag on my site looks like this – <link rel=”stylesheet” type=”text/css” id=”onetidThemeCSS” href=”/_themes/Jet/Jet1011-65001.css?rev=12%2E0%2E0%2E6421″/>. I copied: /_themes/Jet/Jet1011-65001.css?rev=12%2E0%2E0%2E6421
  • Go to the master page settings of your site collection (Site Settings – Look and Feel – Master page)
  • Check the radio button to “Specify a CSS file to be used by this publishing site and all sites that inherit from it”
  • Paste the link we copied previously into the text box
  • Check the checkbox “Reset all subsites to inherit this alternate CSS URL” if you already have subsites created in your site collection.
  • Click OK

Note: If these steps do not work, there is a posibility you do not have the alternate css inhertence setup on your sites. Or, it might mean that you are creating a non-publishing site (like a team site) off of your publishing site collection. Also, if you don’t see some of the links I mentioned in the steps, then that means you either do not have MOSS or you don’t have the publishing features turned on.

Why does this work

SharePoint dynamically creates a _theme folder for a site when you set the theme. Then it associates the theme, through a stylesheet link, in a tag on the sites page. For more information on this process please visit Heather Solomons blog.

The problem is, SharePoint only creates the stylesheet link in the particular site you create the theme at.

Thus, this technique takes advantage of the fact that if you create the theme at the top level site, you can access it through relative paths from any sub-site. So, by creating the theme at the top level site, it will create that _themes folder at that level. Then, luckily, the alternate CSS does inherit through all the sub-sites in SharePoint. So, we can just use a simple relative path, in the alternate CSS, to inherit the theme down through our sub-sites.

Caveat: This is a “no-code” solution for a particular situation (MOSS Publishing Sites). For production systems I always like to do my customizations through solutions, features, custom master pages and custom css. If you don’t have the environment described in this post (MOSS Publishing), then you might have to use other techniques – such as a full customization technique with a solution or by setting the css through designer: Heather Solomons post on CSS Options with Master Pages