SharePoint 2007 – Code blocks are not allowed in this file

Code blocks are not allowed in this file

If you come accross this error, here is the information you need to solve it:

Cause: you are running code snippets inside a file that is not allowed to do so by default.

Afected files: i.e. Master pages and Page layouts

Solution: you have to add an explicit authorization for the file(s) where you want to do so. The question is: do you really want to do it? You should take the best approach which is to add a code behind file (you can find how to do it here: Adding Code-Behind Files to Master Pages and Page Layouts in SharePoint Server 2007). If you still want to do it, just add a tag like this to your :


Using Google Analytics with our SharePoint 2007 publishing site

One of our services wanted to use Google Analytics for their SharePoint (MOSS 2007) intranet.

There’s some good information out there about how to set this up, but I wanted to clarify a few points in the hope of saving others some time.

The basic steps are:

Obtain the Fully Qualified Domain Name (FQDN) for your MOSS site.

Create your Google Analytics account (see detail below). FYI, You don’t need to pass any authentication in order to track hits to your site.

Add the GA tracking code to your site’s master page within the HTML tags, which will allow you to analyze all the sub-pages, not just the home page.

With regard to step 2, when you set up your new account, you need to enter your FQDN in the URL field, and you need to enter it the way they specify:

However, to work with MOSS, what really needs to be entered for the Website URL is the full URL with the /pages/default.aspx ending. Thanks to this post for this information! So you need to go back into the settings once you’ve created the account, and change it. Finding your way into the settings to change the URL is not the most intuitive thing in the world, so I’ve shown it below:

From the home page of your Google Analytics account, click Edit:

Then, in the Profile Settings window, click Edit at the upper right:

At this point you can change your website URL. For the example I’m using, you would enter:


After 24 hours, you should be able to review results on your GA account page.

Force deactivating a feature using STSADM

First log on to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN folder, then run the commands from there (SDSADM.EXE lives in this folder)

Run the following commands to force deactivating and activating the Forms Services feature:
stsadm -o deactivatefeature -filename IPFSSiteFeatures\feature.xml -force -url %SITE_COLLECTION_URL%
stsadm -o deactivatefeature -filename IPFSWebFeatures\feature.xml -force -url %SITE_COLLECTION_URL%
STSADM.EXE -o activatefeature -filename IPFSSiteFeatures\feature.xml -url %Sitecollection_URL% -force
STSADM.EXE -o activatefeature -filename IPFSWebFeatures\feature.xml -url %sitecollection_URL% -force

A quick comparison of the features between WSS 3.0 and MOSS 2007

Features Comparison
Windows SharePoint Services 3.0
SharePoint Office Server 2007
Issue Tracking
The Issue Tracking list template has been updated to use the enhanced versioning and version-history storage features of Windows SharePoint Services 3.0.

Real-time presence and communication
The enhanced real-time presence smart tag icon, displayed virtually everywhere a person’s name appears in the system, tells users whether a person is online and available for a telephone or audio conference call, instant messaging, or two-way video conversation.

Social Networking Web Part
Include Social Networking Web Parts that use information about your organization, communities, and electronic communications in Public My Site pages to help establish connections between colleagues with common interests.

Standard site templates
Windows SharePoint Services 3.0 includes the following standard collaboration site templates:Team siteDocument workspaceBlank siteBlogWikiMeeting workspaces (five workspace types)

A wiki is a new site template in Windows SharePoint Services 3.0 that makes it easy to create, edit, link, and restore an individual Web page. Wikis can be used as creative forums to brainstorm ideas, manage knowledge bases, create designs as well as instruction guides or simply gather information in an easy-to-edit format. Wikis are easy to create, modify, and annotate in addition to tracking contributions and changes. Key features include:Fast and easy page creationEasy and automatic linkingVersion differencesWhat you see is what you get (WYSIWYG) Web page editing

Wikis leverage existing SharePoint functionality including search, navigation, alerts, and custom fields.

Blogs provide a publishing-oriented experience for a single user or a team. Windows SharePoint Services 3.0 includes a site template that supports:Article postingReader commentsArchive viewsRSS feed generation

People and Groups lists
People and Groups offer a unified place to find, communicate with, and manage people and their permissions, including support for custom fields such as Department, “Office #” and Area of Focus; in addition to the new Person field type. The Person field type creates rich displays of lists of people including support for a People Picker for browsing a list of users. Member Group provides:Re-use of groups across sitesDistribution list for the members of the site

Calendars have been enhanced with richer calendar views, expanded support for recurring events, and all-day events.

E-mail integration
Document libraries, discussion boards, calendars, and announcements can be enabled to receive new postings via e-mail. In addition, extensible support is provided for custom e-mail handlers in Windows SharePoint Services 3.0.
Similar to the functionality provided by public folders in Microsoft Exchange Server, e-mail enabled discussion boards support:A highly scalable, topic-based architectureNew “super rich-text” field typeUnified experience for both e-mail and Web-based discussionsOne-step creation of Active Directory directory service distribution lists as part of the site creation processUnified SharePoint group and Active Directory management functions

Task coordination
The new Project Tasks list template provides lightweight task management functionality including Gantt charts for visualization of task relationships and status.

Surveys now include conditional branching as well as support for inserting page breaks in long surveys such as annual employee satisfaction or and customer surveys.

Document collaboration
Improvements to SharePoint document libraries include:
Similar to the functionality provided by public folders in Microsoft Exchange Server, e-mail enabled discussion boards support:Checking out documents locallyOffline document library support in Microsoft Office Outlook 2007Major and minor version numbering and trackingSupport for multiple content typesPolicy, auditing, and workflowTree view support

Enterprise portal

Windows SharePoint Services 3.0
SharePoint Office Server 2007
Integration with Microsoft Office SharePoint Designer 2007
Office SharePoint Designer 2007, based in part on Microsoft FrontPage technology, will provide tools for rich customization of sites, and creating reporting tools and application templates, without any coding.

My Site personal site
The My Site personal site gives users an opportunity to aggregate information “for me,” “by me,” and “about me.” Significant enhancements include social networking, privacy controls, SharePoint Sites and Documents Aggregation Web Parts, and Colleagues and Memberships Web Parts.

Content syndication
Use RSS feeds to syndicate content managed in a portal site.

Privacy and security
Use authorizations to control visibility of information in a My Site public view.

Handling tasks in a workflow

Through this blogpost I’m extending my original workflow project with some additional branching by demonstrating the basic concepts of authoring workflows for MOSS 2007 using the templates provided by Microsoft.
This post demonstrates how and where you would write your code, drop your activities.
Designing our workflow
Lets say I roll a dice. Great! If I get anything over 3, A task and email notification is initiated to notify the originator that they’ve won a prize. Although this is purely an example, this type of functionality could be very useful.
1)    Add an ifElse activity, this should automatically add at least on ifElseBranch activities.
2)    Drag a CreateTask activity under the branch activity. 
Your workflow should now look like this…

Write the code for the WF
Excellent. Now lets get rid of those checkboxes, and write the code for the various activities we dropped.
First, the rolled dice will now have to be accessible all through the workflow. So go ahead and modify the codeActivity1_ExecuteCode method to as below –
private Int32 diceValue= 0;
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
    Random rnd = new Random() ;
   diceValue = rnd.Next(1, 6);
   workflowProperties.Item[“”Title””] = diceValue;
Now that the diceValue is a private variable, go ahead and hover over the red checkmark at the IfElseBranchActivity. It should tell you that the Condition is not set. Go ahead and click on it, and set a “”Declarative Rule Condition”” (simpler) inside of the properties dialog for the IfElseBranchActivity. Expand that tree view for “”Condition””, and click the ellipses by the “”Condition Expression””, and specify a condition as shown below:

You would note that you have full intellisense here. very nice!
The next step is to give flesh to the bones of the createTask1 activity. This is a tad bit tricky. Just tricky, not scary.
First of all, when you hover over the red checkmark by createTaskActivity, it tells you that correlationToken isn’t set. CorrelationTokens are an interesting animal.
So in our case, we have a createTask activitiy, which means, we need to create a NEW correlation token, that applies to Tasks. This ensures that subsequent activities can find that task and act upon it. In order to do so, go to the properties of the createTask1 Activity, and set the correlation token to “”taskToken””.DoNot pick workflowToken as prompted by the drop down. Also set the OwnerActivityName to any parent – I choose Workflow1 (whoaa, a workflow is an activity? yep!).
The next thing to do with createTaskActivity is frankly a tad bit annoying. Double click on the createTaskActivity and it will create a createTask1_MethodInvoking for you. It will also set the createTask1.MethodInvoking property appropriately.
Now what we need to do in the MethodInvoking property, is to set the TaskID (which is a GUID), and TaskProperties. In order to do so, first you need to create two new Fields (not DependencyProperties), that you will use for TaskID and TaskProperties. You can use the following steps to acheive this.
1. Back in WF Designer, right click, properties on the createTask1 activity.
2. In the Properties, click on the ellipsis by TaskID, and go to he Bind to a New Member Tab. Fill in the form as shown below.

3. Repeat the same for TaskProperties, make sure it is bound to a new Field called “”createTask1_TaskProperties1″”
Perfect. Now with these two fields setup, go ahead and modify the code for createTask1_MethodInvoking to as below:
private void createTask1_MethodInvoking(object sender, EventArgs e)
   createTask1_TaskId1 = Guid.NewGuid();
   createTask1_TaskProperties1.AssignedTo = workflowProperties.Originator;
   createTask1_TaskProperties1.Title = “”Congratulations, thou art ye winner!””;
   createTask1_TaskProperties1.Description = “”You have won!!! Now go and claim your prize””;
   createTask1_TaskProperties1.SendEmailNotification = true;
As you can see, I am using the createTask  Activity to send the email to the user. So I don’t need to worry about a sendEmail activity.
So, That’s it, your Workflow1.cs class code should look something like this… 
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Xml.Serialization;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.Office.Workflow.Utility;
namespace CopyAbstractContent
 public sealed partial class Workflow1: SharePointSequentialWorkflowActivity
  public Workflow1()
        public Guid workflowId = default(System.Guid);
        public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties();
        private Int32 diceValue = 0;
        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
            Random rnd = new Random();
            diceValue = rnd.Next(1, 6);
            workflowProperties.Item[“”Title””] = diceValue;
        private void createTask1_MethodInvoking(object sender, EventArgs e)
            createTask1_TaskId1 = Guid.NewGuid();
            createTask1_TaskProperties1.AssignedTo = workflowProperties.Originator;
            createTask1_TaskProperties1.Title = “”Congratulations, thou art ye winner!””;
            createTask1_TaskProperties1.Description = “”You have won!!!! Now go and claim your prize””;
            createTask1_TaskProperties1.SendEmailNotification = true;
        public Guid createTask1_TaskId1 = default(System.Guid);
        public SPWorkflowTaskProperties createTask1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();

Testing the workflow
Now, I have already covered Deploy, Run, Debug, in my previous blogpost, so I won’t waste too much breath on that here. So let us dive straight into “”Enjoy””.
1. Create a new list.
2. Go to List settings, and associate an instance of the Roll Of Dice workflow to that list.
3. Add an item in there
4. Run the workflow you created in #2 above.

Now when I “”win””, i.e. get a value > 3, here is what I get for my Task.

Workflow templates for Visual Studio 2005

Creating MOSS workflows in VS2005 can be cumbersome.  Whist in VS2008 there’s a useful Wizard to take the pain out of creating custom workflows, in VS2005 you need to complete a number of manual processes.
To help move things along, a similar template project has been initiated for developers using VS2005.  The full details can be found on the CodePlex website ….

Removing orphaned site collections from a content database

While deleting a large site collection on the Ver environment the process timed out. This resulted in the site collection being unavailable through a browser but still being listed in the site collection list in Central Admin. However, it was not possible to select the site collection in Central Admin to delete it. Also the command ‘stsadm -enumsites’ reported the following when it came to that site collection:
<Site Error=”The system cannot find the path specified. (Exception from HRESULT: 0x80070003)” />
IISRESET did not fix the problem
The solution was to dettach and reattach the content database from the web application.
Central Admin > Application Mgmt > Content Databases
Select the web application
Open the content database
Make a note of the DB name and the warning and maximum site values
Delete the content database
Add a content database with the values previously recorded
The site collection should no longer be listed in the web application.