Restricting SharePoint 2010 workflow usage and other web application settings

In my last post on managing the throttling settings on your web application we started talking about some of the properties of web application object to restrict resource usage on your portal.

In this post I would like to add few more useful knobs and dials that you can leverage from the object model or PowerShell; in this example I will use PowerShell and connect to my web application:

Open SharePoint 2010 Management Shell and execute the following:

$site = spsite "http://[your site collection URL]"

Now that you got a hold of the SPSite, we’ll access the properties of the parent web application.

For example, here is how to enable or disable user defined workflows which users can create using SharePoint Designer on the site. These workflows cannot add code. They can only reuse code already deployed by the administrator.

$site = spsite "http://[your site collection URL]"

From the Central Administration you can manage workflow settings with this UI:

Another useful setting is the maximum number of items that can be checked in a Cascade or Restrict delete operation. Applicable to lists which have referential integrity enabled in them.

$site = spsite "http://[your site collection URL]"

Along with the CascadeDeleteTimeoutMultiplier property, the CascadeDeleteMaximumItemLimit property controls the duration of a short-term Web site lock that is taken to perform referential integrity delete operations.

Ah, and finally something you probably alway wondered about, how long will the “New!” icon appear beside newly created documents and list items:

$site = spsite "http://[your site collection URL]"

Enjoy!

Get a quick report on SharePoint 2010 Features running in your site collection

Whether you’re doing a routine maintenance or something blew up – it’s quite handy to be able to query your site collection and get a report on features that are running on each of the sub sites.

Just recently I was involved in a troubleshooting of SharePoint Content Deployment job which failed reporting a feature not activated on one of the farms – the farm had over 1.. sites – so finding the feature using UI would have been very painful.

Fortunately SPSite has a method allowing you to query features on site collection and subwebs called QueryFeatures, among other , QueryFeatures(Guid) is quite handy when looking for a specific GUID.

Here is how something like think can be used in PowerShell to find sites that have calendar feature enabled:

PS C:\Users\yar> $site = spsite "http://yar2.1."
PS C:\Users\yar> $site.QueryFeatures("..BFEA71-EC85-49.3-972D-EBE47578.1.6")
As a result I get:

DefinitionId           : ..bfea71-ec85-49.3-972d-ebe47578.1.6
Parent                 : Demo
Properties             : {}
Definition             : SPFeatureDefinition Name=FeatureDefinition/..bfea71-ec
85-49.3-972d-ebe47578.1.6
Version                : 3....
FeatureDefinitionScope : Farm
DefinitionId           : ..bfea71-ec85-49.3-972d-ebe47578.1.6
Parent                 : Search
Properties             : {}
Definition             : SPFeatureDefinition Name=FeatureDefinition/..bfea71-ec
85-49.3-972d-ebe47578.1.6
Version                : 3....
FeatureDefinitionScope : Farm
Enjoy!

PowerShell: Manage resource throttling for SharePoint 2010 Web Application setting

One of the improvements in SharePoint 2010 is granularity on managing resource throttling for your web applications.

If you navigate to Central Administration -> Manage Web Applications -> select web application, you will have an option on a ribbon to manage web application settings and throttling is one of the options.

When you perform an automated deployment – you probably want to set most of the settings here using a script or code.

Here are options I found useful to be able to set using PowerShell.

Open SharePoint 2010 Command Shell and connect to your site collection:

$site = spsite "http://[your site collection URL]"

Here are some other options you might want to set using PowerShell or object model:
List View Threshold
Specify the maximum number of items that a database operation can involve at one time. Operations that exceed limit are prohibited.

$site = spsite "http://[your site collection URL]"

List View Threshold for Auditors and Administrators
Specify the maximum number of items that an object model database query can involve at one time for users to whom you grant sufficient permissions through Security Policy.
$site = spsite "http://[your site collection URL]"

Object Model Override
If you choose to allow object model override, users to whom you grant sufficient permission can override the List View Threshold programmatically for particular queries.
$site = spsite "http://[your site collection URL]"

List View Lookup Threshold
Specify the maximum number of Lookup, Person/Group, or workflow status fields that a database query can involve at one time.
$site = spsite "http://[your site collection URL]"

More to follow .. enjoy!

SharePoint automation with PowerShell: replacing properties of web parts in sites of a site collection

As you maintain your SharePoint 2010 site, over time you may be changing properties of web parts that appear on the site. Whether those have been developed in house or third party – if the instance of the web part appears in 50 pages in the site – it can be a real challenge to modify the properties of them manually.

Creating custom solution that will provision the change programmatically can be an option but there is a down time associated with such solution deployment which can be an issue if your site is in production.

In this example I will share a PowerShell script which will iterate through the publishing sites in the site collection and update the properties of the Content Editor web part. When done – the page will be checked back in and published to the site.

In the part of the script below I will show only the part where we change the properties of the web part – the rest of the working script you can download from here:

function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
if($webpartmanager.GetType() -eq [
Microsoft.SharePoint.WebPartPages.ContentEditorWebPart])
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)
function UpdateWebpart([Microsoft.SharePoint.Page]$page)

In here we’re checking whether the type of the web part is the Content Editor WP. In your case you will probably check for some other criteria as well as make updates to your own properties. To test the script – download and run it from here.

The script assumes – you’re in publishing environment and will ignore all of the collaboration sites.

Enjoy!

Leveraging synchronous and asynchronous event receivers in SharePoint 2010

When adding a new event receiver to a SharePoint 2010 entity with Visual Studio 2010 you get variety of events – some of which are synchronous and some asynchronous.

What’s the difference and when to use which? Synchronous events the event in the same thread before sending the Web response back to the browser. Asynchronous events are run by a separate thread, so processing does not block the flow of code execution.

For example, an ItemAdding event is always synchronous – because in your code you may want to change the course of actions (you can cancel the event or change the item properties). In such case the thread will wait to see what you have decided to do.

In other case ItemAdded, can be asynchronous or synchronous and when adding a new receiver to the solution, in the Elements.xml of your receiver definition you can specify the value of Synchronization:

..
<Class>SharePointProject1.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
<Synchronization>Synchronous</Synchronization>      
</Receiver>

So what does this all mean? If you create two event receivers for the same event for the same list (or anything else for that matter) – the synchronous event will take precedence. If both events are synchronous – the order will depend on the sequence specified in the definition Elements.xml.

You also might want to know that you can not make the event, such ItemAdding, which is synchronous by default to be asynchronous, otherwise you will get an exception during the deployment with the following error:

Error occurred in deployment step 'Activate Features': Operation is 
not valid due to the current state of the object.

Good Luck!

Enabling multi-tenant hosting in SharePoint 2010

SharePoint 200 allows for multi-tenant hosting, which means you can have subscribers in your farm representing separate entities which can host their own sandbox solutions and subscribe to one or more service applications.

As an example of usage for such feature you can think of an organization with the centralized farm but separate departments requiring access to different services and requiring separation data and flexibility to manage their own usage quota and permissions.

This feature is not enabled by default and there few steps involved in provisioning multi-tenancy.

Open SharePoint 200 Management Shell
2. Execute below to start multi-tenancy service

Get-SPServiceInstance | where{$_.Name -eq 
"SPSubscriptionSettingsServiceInstance"} | Start-SPServiceInstance 

3. Choose a managed account to create a proxy for the multi-tenancy service application

$sub = New-SPSiteSubscription

4. Create new application pool which is going to handle the service

$sub = New-SPSiteSubscription

5. Create an instance of the service application

$app = New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPool 
–Name MultitenancyServiceApp -DatabaseName MultitenancyServiceDB

6. Create a proxy for the service application

$proxy = New-SPSubscriptionSettingsServiceApplicationProxy 
-ServiceApplication $app

Now, we can create new subscriptions and site collections

Execute the following in the SharePoint PowerShell to create a subscription:

$sub = New-SPSiteSubscription

2. Create tenant administration site where you can create and manage tenant site collections

New-SPSite -url http://yar200/sites/tenants-owneralias sandbox\yar 
-owneremail yar@sandbox.com-template tenantadmin#0 
-SiteSubscription $sub -AdministrationSiteType TenantAdministration

Here is how the UI will look like

3. Now we can create new site collections r manage existing ones from this UI or if you’re doing automatic provisioning using same powershell script as above :

New-SPSite -url http://yar200/sites/member-owneralias sandbox\yar 
-owneremail yar@sandbox.com-template sts#0 -SiteSubscription $sub

Remember that the subscription value is required when creating new site collection with PowerShell or programmatically so that the new entity is associated with the right subscription and tenant administration site.

Good Luck!

Getting started with SharePoint 2010 site analytics and usage statistics

One the many other social features in SharePoint 2010 (few of which we customized in my book) is SharePoint 2010 site and web analytics functionality.

To enable data collection your site: 1. Navigate to Central Administration.
2. Click Configuration Wizards and start farm configuration wizard
3. From the list of available applications – pick Usage and Health data collection and click Next to set it up

By default data collection runs daily which you can adjust by changing the schedule of the timer job:

1. From the Central Administration navigate to Monitoring
2. Click Review job definitions
3. Find the definition called Microsoft SharePoint Foundation Usage Data Processing
4. Adjust the time to your liking or run the data collection.

After you let the job running for a while you can navigate to the analytics reports in your site to see results:

Site Actions -> Site Settings -> Site Web Analytics reports

If you ran the timer ob after you used the site for a while – you will get usage data displayed. Although the UI displaying report and a graph is a web part – this web part can not be extended or configured or even placed on another page without custom code.

However, there is another web part – which you can add to any zone of the page: Content Rollup -> Web Analytics Web Part.

You get access to some of the handy properties allowing you to poll most popular pages or most searched content on the site:

Give it a try!

SharePoint 2010 Branding: Creating and deploying themes

In the last episode on SharePoint 2010 branding we looked at deploying your custom masterpages and CSS.

In this short video on SharePoint 2010 branding we’ll take a at how you can deploy your custom themes using Visual Studio 2010 and manually. The solution we’re using in Visual Studio is built in the way that you can upload themes to the cloud provider if you’re using cloud hosted SharePoint. For more info on deployment with PowerShell script – check my new book with associated source code.

SharePoint 2010 Branding: Creating and deploying themes from Yaroslav Pentsarskyy on Vimeo.

How To: Enable or Disable sandbox solutions in your SharePoint 2010 farm

In SharePoint 2010 we have a brand new concept of sandbox solutions – which I have been writing about for a while now. In your farm you may want to disable sandbox upload to avoid even power users uploading custom solutions from potentially untrusted source.

Alternatively, as a developer you may be developing a solution which is going to live in the cloud and you need to develop and debug it in sandbox mode to make the environment match the cloud provider’s environment.

Whichever is the case – you need to the service allowing sandbox solutions is enabled in your farm.

If you navigate to the Services snap-in of your server – you can see the status of the service there:

However, don’t disable or enable the service from there. Instead, navigate to your SharePoint 2010 Central Administration -> System Settings -> Manage Services on Server

In here you will see Microsoft SharePoint Foundation Sandboxed Code Service and option to enable or disable it:

One you start or stop the service – the service in Services snap-in will also get updated automatically.

With the service disabled you will get the following error trying to deploy the solution to the site using Visual Studio 2010:

Error occurred in deployment step 'Activate Features': Cannot start service SPUserCodeV4 on computer

From the UI (Site Actions -> Site Settings -> Solutions) – you will be able to upload new sandbox solution but you won’t be able to activate it with the tip that you may not have the right permission level :

Good Luck!

First chapter: Automated SharePoint 2010 solution deployment and more

Recently many of you requested to have a preview of my new book.

As some of you already know the book is very hands on and gives away a lot of neat scripts and handy code – I decided to upload the entire first chapter for you to take a read and see what’s in it for you.

First chapter talks about the following:

  • Solution Packaging – Discusses various approaches on structuring your visual studio solution to optimize and simplify your deployment and further upgrades.
  • Custom Solution Deployment Script – deployment script that does it all, written in PowerShell so you can make changes and customizations to suit your particular scenario.
  • Referenced Assemblies in Your SharePoint Solution – How do you include third party and internal assemblies with your package deployment
  • Debugging Your SharePoint Applications – talks about various techniques allowing you to debug your SharePoint application quickly and efficiently.

Check out what other topics are discussed in the book and see the sample source code in the downloads section of this site.

Enjoy!