07/12/2012

SharePoint 2010 Workflows

SharePoint 2010 Workflows - termination and cancellation


Cancelling a workflow stops the workflow, but all tasks connected to the workflow is still there.
Terminating a workflow stops the workflow and roll back or delete all tasks.

Some times termination does not work the correct way and email notifications are still sent to the task owners.

In the database the workflows are stored in the Workflow table. The Workflow table contains a column named InternalState, the value in this column are set by using the SPWorkflowState enum. When InternalState is 128 the workflow is terminated. The SPWorkflowState enum have these values:

public enum SPWorkflowState
{
    None = 0,
    Locked = 1,
    Running = 2,
    Completed = 4,
    Cancelled = 8,
    Expiring = 16,
    Expired = 32,
    Faulting = 64,
    Terminated = 128,
    Suspended = 256,
    Orphaned = 512,
    HasNewEvents = 1024,
    NotStarted = 2048,
    All = NotStarted | HasNewEvents | Orphaned | Suspended | Terminated | Faulting | Expired | Expiring | Cancelled | Completed | Running | Locked, /* 4098 */
}

The workflow state can be changed by using the WorkFlow API: SPWorkflowManager.CancelWorkflow

User Profiles

User Profile Permissions


Central Admin > Application Management > Manage service applications

Click on Administrators:




Add, remove or change User Profile Permissions.

04/12/2012

SharePoint 2010 Document Sets

Document sets basics


Document sets are a part of SharePoint Document Management. Document Set enables grouping multiple documents, that support a single project or task, together into a single entity. A document set can in many ways be thought of as a folder, but a document set has some additional features:
  • Share the meta data
  • Can be versioned
  • Document sets use Content Types, Document set Content Types, you can create your own custom document set content type, a Document Set can therefor have all Content Types features (information policies, workflows and meta data)
  • Shares a common home page
Examples:

Test Document Set

A test Document Set can be created to group all test documents related to an application. Allowed Content Types in a test Document Set can be Test descriptions (step by step test steps), Test Reports (results of a test run through) and Test Plans (plans for how, who and when to run the tests).
The Test Document Set can contain a column named category, this category can always be set to "Test documentation" when documents are added to the document set. As an alternative the Document Set may contain only test documents connected to a specific release. The document set can then have another property named release version. This property can also be propagated down to all contained documents. The Test Document Set should have a description containing what documents should be placed in the set.

Design Document Set

A design Document Set can be used as a group of design documentation and supporting documents. The allowed Content Types would typically be Design Document Content Type and maybe a general Content Type used for all supporting documents. A periodic review workflow shall be associated with the document set to ensure that the documents are reviewed each year.

Department Budget Document Set:

A Document Set containing all budgets for 2012 for a specific department and sub departments.


How to create a Document Set Content Type

The document set feature must be activate: Site Settings > Site Collection Features:



Create a new document set: Site Settings > Galleries > Content Types > Create, the document set Content Types are displayed in the Document Set Content Types group:


When the new document set is created start by adding columns, click on Add from existing site columns or Add from new site column. Set the columns to required or not (click on the column after it is created):

Possible Document Set settings:
  • Restrict the Content Types allowed in the document set by setting the Allowed Content Types: the default settings are that only documents with Content Type document are allowed
  • Default Content: is there any content that always shall be added to the document set when created?
  • Consider if each file in a document set shall be prefixed by the name of the Document Set
  • Which column values for the Document Set should be automatically synchronised to all documents contained in the set? If a property is set for the document set this can be synchronised to all containing documents.
  • Consider what properties shall be shown on the welcome page: the welcome page is shown when opening the document set, a default welcome page is shown below
  • Customise the welcome page: you can change the text and image shown
Associate the new Document Set Content Type with a document library: Library > Library Settings > Add from existing Site Content Types. Choose Content Type Group and add it.

Now try to create a new document set. Go to the library, choose Documents > New Document > My Document Set:

Set name and properties of your new document set.

The new document set with the default welcome page will look like this:

 

Add a new document to the document set: Documents > New Document > Document, notice that the only Content Type allowed is Document:


The Document Set appears like this in the library:

SharePoint 2010 Content Types

Content Types basics


A content type is a reusable collection of meta data (columns), workflow, behaviour, and other settings for a category of items or documents in a list or document library. Content types enable you to manage the settings for a category of information in a centralised, reusable way. A content type defines the attributes of a list item, a document, a document set or a folder.

Example of a content type: Test description document content type:

Test description is a document containing step by step test steps that is used when testing an application.The test description Content Type is used for test description documents in a document library that contains system related documentation.
All test descriptions must be tagged with what system the test description tests and who is the owner of the document. These are properties associated with the test description Content Type.
All test descriptions has the same document headings, document header and document footer. It is therefor created a test description document template. This template is associated with the test description Content Type. When creating a new test description in the document library this template is automatically used.
A periodic review is associated with the test description, a review is forced on the document owner before every release of the system (released periodically). This is a workflow associated with the Content Type.
For traceability reasons auditing is also required, every time a test description is changed the id of the test description document is logged. This is an Auditing Policy associated with the Content Type.
The id associated with the Content Type is prefixed with TDD (Test Description Document), this is an example of a custom feature of this Content Type.

This can be specified for a content type:
  • Properties to associate with items of its type: columns of the content type, these are displayed when a new document is created and when the document is shown in the document list. The columns are also shown in the Document Information Panel in Office products. Columns can be reused.
  • Metadata to associate with items of its type: Metadata is information about a document that is used to categorise and classify your content. Metadata is associated with a content type as a column. A column can be mandatory to ensure that the meta data is provided.
  • Workflows that can be started from items of its type: e.g. periodic workflow review
  • Information management policies to associate with items of its type: 
    • auditing: logging when an event occurs
    • retention policies: define retention stages and an action that happens at the end of each stage, e.g. moving the item to the Recycle Bin, deleting an item or moving an item to another location
    • labels to ensure that physical copies of each document are properly identifiable
    • print restrictions, to ensure that sensitive employee-related documents are printed only on secure printers 
  • Document templates (for document content types)
  • Custom features: e.g. changing the id pattern
Document libraries and lists can contain multiple content types. SharePoint comes with a set of OOTB Content Types. Content types are organised into a hierarchy that lets one content type inherit its characteristics from another content type. Content types can be shared on different SharePoint sites.

21/11/2012

Adding your custom styles in your SharePoint 2010 Rich Html Editor

This blog post describes how to add a custom styles in your Rich Html Editors.

The new style will appear when editing e.g. a wiki or site page in the Markup-Style dropdown:

 
 
Or in the Table-Style drop down:
 


1: Create the style
Add CSS file to managed folder /layouts/Namespace/wiki.css

Example headings (Markup-Style dropdown):

H1.ms-rteElement-MyH1
{
    /* This name will be displayed in the drop down */
    -ms-name: "My heading 1";
}
.ms-rteElement-MyH1
{
    background-color: #597087;
    color: #ffffff;
}

Example tables (Table-Style drop down) - Table with coloured header row and zebra stripes:

.ms-rteTable-10,
.ms-rteTableHeaderFirstCol-10,
.ms-rteTableHeaderLastCol-10,
.ms-rteTableHeaderOddCol-10,
.ms-rteTableHeaderEvenCol-10,
.ms-rteTableFirstCol-10,
.ms-rteTableLastCol-10,
.ms-rteTableOddCol-10,
.ms-rteTableEvenCol-10,
.ms-rteTableFooterFirstCol-10,
.ms-rteTableFooterLastCol-10,
.ms-rteTableFooterOddCol-10,
.ms-rteTableFooterEvenCol-10,
TD.ms-rteTable-10,
TH.ms-rteTable-10,
.ms-rtetablecells
{
    /* This name is displayed in the drop down */
    -ms-name:"Table Style 4 - Zebra stripes";
    border-left: none;
    border-right: none;
    text-align:left;
    line-height:2;
    vertical-align: top;
    padding:2px;
    padding-left: 5px;
}
.ms-rteTableHeaderFirstCol-10,
.ms-rteTableHeaderLastCol-10,
.ms-rteTableHeaderOddCol-10,
.ms-rteTableHeaderEvenCol-10
{
    background-color: #b5c1ce;
    color: white;
    border-top: solid #D5DCE3 1px; 
    border-bottom: solid #D5DCE3 1px;
}
.ms-rteTableFooterFirstCol-10,
.ms-rteTableFooterLastCol-10,
.ms-rteTableFooterOddCol-10,
.ms-rteTableFooterEvenCol-10
{
    font-weight: bold;
    border-top: solid #D5DCE3 2px; 
    border-bottom: solid #D5DCE3 2px;
}
.ms-rteTableFirstCol-10, 
.ms-rteTableLastCol-10
{
    font-weight: bold;
}
.ms-rteTable-10 tr.ms-rteTableOddRow-10 {
 background-color: #eee;
}
.ms-rteTable-10 tr.ms-rteTableEvenRow-10 {
 background-color: #fff;
}

2: Add Css to master page or default page layout

<SharePoint:CssRegistration ID="CssRegistrationWiki" 
   name="/_layouts/Namespace/wiki.css"  After="corev4.css" runat="server"/>3: 


It is not possible to remove any existing table or heading styles. You can change existing style or add new styles, but not delete. Also, it is not possible to change the name of an existing style.

A common thing you would like to do is change the default table style, this can be done by using "-default" instead of "-10" in the style selectors in the example above. But remember that the name of the default table style will never be changed.

There is a way to do this but it requires you to add a parameter every place the "PublishingWebControls:RichHtmlField" field is used, see this blog post at sharepoint blues.

08/11/2012

"Cannot uninstall Language Pack" and Unexpected System.NullReferenceException when trying to access the web site

How to fix this error

The message "Cannot uninstall Language Pack" appears when doing Uninstall-SPSolution and an Unexpected System.NullReferenceException appears when trying to access the web site. This error may only be present on one of the servers in a farm.
  1. Stop the SharePoint Timer Service (OWSTIMER).
  2. On the problem server, navigate to:
    1. Windows Server 2003 location: Drive:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\GUID and delete all the XML files from the directory.
    2. Windows Server 2008 location: Drive:\ProgramData\Microsoft\SharePoint\Config\GUID and delete all the XML files from the directory.
  3. Delete all the XML files in the directory or sub directories, not the .INI file.
  4. Open the cache.ini with Notepad and reset the number to 1. Save and close the file.
  5. Start the service on the server and wait for XML files to begin to reappear.
  6. IIS Reset

07/11/2012

Styling a list as a comma separated string


The requirement was to create a history trail of visited pages in a SharePoint Enterprise wiki. The result will look like this:

Your trail: Page1, Page2, Page3

The HTML:

<div class="historyTrail">
    <div class="historyListHeading">Your trail: </div>
    <ul id="historyTrailList">
        <li>Page1</li>
        <li>Page2</li>
        <li>Page3</li>
    </ul>
</div>

The CSS:

.historyTrail
{
    display: block;
    margin-bottom: 20px;
}
.historyListHeading 
{
    display: inline;
}
.historyTrailList
{
    display: inline;
    list-style: none;
    margin-left: -30px;
}
.historyTrailList li
{
    display: inline;
}
.historyTrailList li + li:before {
    content: ", ";
}

Easy as that!

Create custom enterprise wiki

How to create a custom enterprise wiki


1: Create a web template that extends the enterprise wiki template:

<?xml version="1.0" encoding="utf-8"?>
<Templates xmlns:ows="Microsoft SharePoint">
    <Template Name="YourWiki" ID="0">
        <Configuration ID="0"
                       Title="Your Enterprise Wiki"
                       Hidden="FALSE"
                       ImageUrl="/_layouts/images/stts.png"
                       Description="..."
                       DisplayCategory="Custom"
                       ProvisionClass="<Namespace>.YourProvider"
                       ProvisionAssembly="<namespace>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx" 
                       RootWebOnly="False">
        </Configuration>
    </Template>
</Templates>

2: Deploy the custom template to the folder: {SharePointRoot}\Template\1033\XML

3: Create the Custom Provider class:

class YourProvider : SPWebProvisioningProvider
{
    public override void Provision(SPWebProvisioningProperties props)
    {
        props.Web.ApplyWebTemplate("ENTERWIKI#0")
        var code = new SPSecurity.CodeToRunElevated(CreateSite);
        SPSecurity.RunWithElevatedPrivileges(code); //Excecute elevated
    }
    private void CreateSite() 
    {
        using (SPSite site = new SPSite(Properties.Web.Site.ID))
        {
            using (SPWeb web = site.OpenWeb(Properties.Web.ID))
            {
                // your custom code
            }
        }
    }     
}

That's it :)