Monday, April 4, 2011

Configuration of the Microsoft SharePoint Server State Service using PowerShell

If you are trying to develop new InfoPath 2010 form and after deployment you are receiving the following errors:

"SharePoint 2010 The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator."

"InfoPath Forms Services not working due to invalid State Service configuration - Event 7898"


Then you need to configure the State Service. There are 2 options:

Option 1: Using PowerShell command
Open SharePoint Management Shell and type the following commands:

$serviceApp = New-SPStateServiceApplication -Name "State Service"

New-SPStateServiceDatabase -Name "StateServiceDatabase" -ServiceApplication $serviceApp

New-SPStateServiceApplicationProxy -Name "State Service" -ServiceApplication $serviceApp -DefaultProxyGroup

Option 2: Using "Farm Configuration Wizard" (however this approach is highly NOT recommended...) 
  • launch the "Farm Configuration Wizard" from Central Admin
  • click Start the Wizard 
  • select the State Service check box and click "Next"
  • click Finish

 One note here: if the State Service is greyed out, this means that it is already configured and the only way to change it is using PowerShell commands. Once configured it can not be retracted using Farm Configuration Wizard


Thursday, March 3, 2011

How to deploy a .UDCX file to a Data Connection Library using correct ListId

I'll try to give workaround on one of the most common problems related with InfoPath deployment. Probably everybody who had deployed InfoPath forms before knows about it.


The Problem: deploying InfoPath Forms to production
Once development is done, we need to move the form template from development to production. The problem is that we don't know the ListId in advance. According Universal Data Connection v2.0 Reference and Schema in MSDN the .UDCX file has the following structure:


<?MicrosoftWindowsSharePointServices ContentTypeID=”0x010100B4CBD48E029A4ad8B62CB0E41868F2B0”?>
<udc:DataSource MajorVersion="2" MinorVersion="0" xmlns:udc="http://schemas.microsoft.com/office/infopath/2006/udc">
    <udc:Name>Main submit</udc:Name>
    <udc:Description>Format: UDC V2; Connection Type: SharePointLibrary; 
Purpose: WriteOnly; Generated by Microsoft Office InfoPath 2007 on 2010-07-13 at 16:04:26 by 
DEV\svc_mossfarm_vm0150.</udc:Description>
    <udc:Type MajorVersion="2" MinorVersion="0" Type="SharePointLibrary">
        <udc:SubType MajorVersion="0" MinorVersion="0" Type=""/>
    </udc:Type>
    <udc:ConnectionInfo Purpose="WriteOnly" AltDataSource="">
        <udc:WsdlUrl/>
        <udc:SelectCommand>
            <udc:ListId/>
            <udc:WebUrl/>
            <udc:ConnectionString/>
            <udc:ServiceUrl UseFormsServiceProxy="false"/>
            <udc:SoapAction/>
            <udc:Query/>
        </udc:SelectCommand>
        <udc:UpdateCommand>
            <udc:ServiceUrl UseFormsServiceProxy="false"/>
            <udc:SoapAction/>
            <udc:Submit/>
            <udc:FileName>Specify a filename or formula</udc:FileName>
            <udc:FolderName AllowOverwrite="1">/Lists/SubmittedFormsLib/</udc:FolderName>
        </udc:UpdateCommand>
        <!--udc:Authentication><udc:SSO AppId='' CredentialType='' /></udc:Authentication-->
    </udc:ConnectionInfo>
</udc:DataSource>
 

Let's focus on  the ConnectionInfo Element and especially on the SelectCommand Element


Most common practice is to generate this .UDCX file with InfoPath using the Convert button on the Data Sources form. Once converted the ListId element is hard coded with the GUID of a list... cool, uh? That makes the .UDCX file absolutely useless when we need to deploy it to some other server.


Suggested solution
I read numerous articles describing that specifying a list by name in an .UDCX file instead of the ListId works fine, but actually I never managed to make it work.
Even I tried with the name of the list, the internal name of the List, relative path of the list, absolute path.... it never get working. I was still receiving an error when I open the InfoPath form.

So finally I stop trying to find a working "hack". In my vision putting ListName when it is explicitly specified in MSDN that the .UDCX file expect ListId is either bug in SharePoint or "hack"

My workaround
As replacing ListId with Name doesn't work for me I created new feature that basically read all of the files in the Data Connection Library and manually update the relevant List IDs

First of all we need these steps:
  • Create new feature that deploy the InfoPath Forms
  • Create new feature that deploy the InfoPath Data Connection Files (.UDCX)
  • Create new feature that update uploaded .UDCX files
  • Add EventReceiver to our InfoPathDataConnectionUpdate feature
  • Add Feature Activation Dependency (we need InfoPathDataConnection feature to be activated before InfoPathDataConnectionUpdate)
And here is that we have in our InfoPathDataConnectionUpdate.EventReceiver.cs


First let's define 2 constants that we need. Infopath Data Connections library is standard out of the box library, so we search for it by name (no need to use GUID in this case)





And here is our method UpdateDataConnectionLibrary that actually get the connection file and simply update the xml node that contains the ListId. Have in mind that in my solution the names of the Lists are exactly the same as the names of the .UDCX files:


So for all of these .UDCX files I have coresponding lists/libraries that are names exactly the same way:
ApplicationsUsed
Criticality
Effectiveness
....

This way in the event receiver simply use the item.DisplayName in the foreach
foreach (SPListItem item in web.Lists[InfopathDataConnections].Items)
{
       //Main Submit udcx is used for submit only. No need to update ListID
       if (item.DisplayName == "Main Submit") continue;
   
      UpdateDataConnectionLibrary(web, item.File, item.DisplayName);
}

Otherwise you should create your own mapping that map the .udcx file with the corresponding SharePoint list. Anyway best practice is to have exactly the same list name as the data connection file

You can download the event receiver from here

Saturday, January 1, 2011

SharePoint 2010 Backup/Restore farm

Following article will show how to backup/restore SharePoint 2010 farms using shell script.
Power Shell Commands
Here are the shell commands that are used to backup/restore: 
Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential}
Restore-SPFarm -Directory <BackupFolder> -RestoreMethod Overwrite

Considerations and Prerequisites

First of all let’s start with little guidance about backup/restore procedures:
  • By design to restore a database is required at least 1 Full backup and the rest can be only Incremental backups. In order to save space we can perform Full backups on weekly bases and Incremental on backups on daily bases. However for large databases incremental backups are recommended.
  • Store a copy of backup files off-site
  • Backups should not be performed during operation hours to prevent data loss
  • Farm administrator account needed to perform the backup/restore operations
  • Valid AD accounts required to be used for SharePoint service accounts. Otherwise after restore the farm will not be operational. 

Backup procedure:

·         Open SharePoint Management Shell and type the command
    Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential}



Restore procedure

Open SharePoint Management Shell and type the command
Restore-SPFarm -Directory <BackupFolder> -RestoreMethod Overwrite
(command and parameters can be entered separately like below)



Then SharePoint will automatically list all Web Applications that are found in the backup:

Then SharePoint will ask user to provide credentials for the accounts that will be used to run the SharePoint Services. Depends on the installed services before the backup there are different accounts that needs to be provided. Few of the required accounts (listed as an example):
 - SP config account
- SP application pool account
- SP Search account
(below shown SP asking for Shared Services Application account)
 

Limitations of backup/restore

  • You cannot restore a multiple-server farm to a single-server farm or a single-server farm to a multiple-server farm
  • You cannot back up from one version of Microsoft SharePoint Server and restore to another version of SharePoint Server
  • Configuration and Central Administration content databases are not being restored by design from Microsoft SharePoint Server 2010 tools. There are 2 options to move  configuration databases (SP_Config):
o   Manually restore using SQL Manager
o   Install and configure SharePoint on the new environment, so it has its own configuration database and re-configure it.  LDP ha only few custom configurations that needs attention – Shared Services Provider (SSP), Search configuration and schedule, AD connector
  • Some of the service applications cannot be started automatically after  the restore operation and needs to be started manually (Using Central Administration or Power Shell)
  • Servers should have identical components installed! For example if you backup SharePoint farm with Enterprise Edition, Fast Search and BDC Connector configured, this backup cannot be restored on server with SharePoint Server Standard or Foundation or on server without Fast Search.

Useful links:
http://technet.microsoft.com/en-us/library/ee428316.aspx

http://technet.microsoft.com/en-us/library/ff607965.aspx

Sunday, December 12, 2010

How to create really cool SharePoint 2010 page: tips & tricks

Branding of the site is one of the most important tasks for every SharePoint project. These days everybody is using SharePoint for collaboration... every day...every hour.. even every minute. SharePoint become an essential part of the working day. In other word branding is important. 


What is the main goal of this posting. Probably every body knows how the standard Team Site looks:
After reading this post, you will be able to create really cool home page in an hour. This is what we are trying to achieve:
  
So... everything we need is: SharePoint Designer 2010, Microsoft Office 2010 and MS Paint. I like more www.paint.net but the good developer can use any tool!


First time when I've done custom design of SharePoint site, I've been struggling a lot... SharePoint Designer 2007 was not that good, so I messed up the things and broke the whole site, because I drag & drop some content by chance.  These days are gone...Microsoft finally did excellent job especially when somebody need to customize the master pages.

Before the actual work, let's quickly describe the 5 simple steps we are going to do:
  1. Create new theme in PowerPoint and then import into SharePoint
  2. Add custom CSS class in the master page
  3. Create few additional images that will be used for backgrounds
  4. Redesign some of the SharePoint build-in elements
  5. Add some fancy content to the home page   
So after a brief summary we are ready to start....3....2....1....go:
    Step 1: Create new theme in PowerPoint and then import into SharePointIn 2010 you can create theme in any Microsoft Office application you have around: Word, PowerPoint....just export and import in SharePoint. So let's open PowerPoint, create new theme and save it to our local PC:

    Then we can enter some colors.... If you don't know what these colors and accents means have a look at this picture. I believe in visual mapping - you need to see where it stands in order to know what color to put. good news is that you can always modify the theme from SharePoint and use the preview option (even it is working a kind of slow...)


    In this particular presentation I used these colors (all files supplied at the end of the presentation)
    Now all need to export the .thmx file and import it in SharePoint ... that's it. Simple enough ;) ?
    To upload the theme into Theme Gallery either go to /_catalogs/theme/Forms/AllItems.aspx or:
    1. Open your SharePoint site
    2. Click Site Actions
    3. Click Site Settings
    4. In the Look and Feel section, click Site theme
    5. At the top of the page click the Theme Gallery link
    6. Click the Documents tab
    7. Click Upload Document
    8. Click Browse
    9. Browse to the MyCustomTheme.thmx file you created and select it
    10. Click OK
    11. Click Save

    Now the new theme will appear in the Theme Gallery . So let's go and apply the new theme to the site:
    1. Go to Site Actions -> Site Settings 
    2. In the Look and Feel section click "Site theme"
    3. In the "Select a Theme" section select the theme we just uploaded. 
    4. Click apply
    And we are done with our custom theme. This is a good starting point. Here is how the site looks like after we applied the theme:

    Step 2: Add custom CSS class  
    At this point we need SharePoint Designer ... so.... go ahead and click "Edit the site in SharePoint Designer".
    Before doing any change I would strongly recommend to create new master page and copy the content from the default v4.master. It is useful to have v4.master in case you need to roll-back some changes or check some placeholder name/position.


    The easiest way is referencing your custom CSS in the header:
    • Edit the master page in advanced mode.
    • paste in the following in the <head> section:
    • <SharePoint:CssRegistration name="/Style Library/Common.css" After="corev4.css" runat="server"/>
    • Save/Publish the page. At this point the site will now have the custom CSS applied.
     
    Step 3: Create few additional images that will be used for backgrounds


    One of the things I dislike a lot is the headers of the list in sharepoint. I know they are a way better then 2007, but still I don't like them. So every time I create new branding site, I put some custom backgrounds for the headers that override the dynamically generated header images from SharePoint.


    The easiest way is to create a small image that can be used for background. Here is what I am doing. After applying the theme SharePoint automatically generate the faded images that are used for backgound of the headers.
    I like the styling of the SharePoint dialog box, so using FastStone Capture or paint.net (find link at the bottom of this article) I just cut a small piece of it that I am going to use as a background for all headers 


    Using this approach I created 4 different background images that we will apply:
     

    All images that were created can be found at the bottom of the page in attached zip file.


    Step 4: Redesign some of the SharePoint build-in elements 
    I am going to do some modifications on the page. Let's do it step by step
    1. Move the ribbon below the top menu. I have separate posting on this topic...
      How to move the whole ribbon row
    2. Change the background of the top area - this way we gonna add some nice fading. Let's do it by overriding the CSS class generated by SharePoint. First let's see what is the current class applied to the top header.
      - open the site in FireFox and turn on FireBug
      - select the top are, right click and choose the option "Inspect Element"



    3.  
    4. This way we can see that the class that set the background image ans we need to override is .s4-title
      So let's just add some custom background image and some custom background color:
      .s4-title
      {
          background-image:url('/SiteAssets/top_nav_bg.png');
          background-repeat: repeat-y;
          background-color: #7B6194;
      }  

      Using the same approach (grab the class using FireBug and override the CSS) we basically create additional styling for left menu, for top menu and all headers of the SharePoint elements. Let's show it again:
      step 1: Grab the required class with FireBug (right click and choose "Inspect Element")
      step 2: find the appropriate class we need to override:

      step 3: create custom CSS class that override it:
      .ms-WPHeader
      {
          background-image: url("/SiteAssets/top_nav_bg.png");
          background-position: right top;
          background-repeat: repeat-x; 
          height:27px;
      }
      step 4: add it to our Custom.css
    5. Use the same procedure to:
      • move breadcrumbs and site description to the right side of the header (this way the logo will stay on the left). Here is the CSS:
        .s4-titletext
        {
            text-align: right;
        }
      • add custom background image to the left menu area:
        .ms-quickLaunch
        {
            background-image: url("/SiteAssets/side_bar_bg.png");
            background-position: right top;
            background-repeat: repeat-y; 
        }
      • add custom background image to left menu headers:
        #s4-leftpanel-content
        {
            background-image: url("top_nav_bg.png");
            background-position: right top;
            background-repeat: repeat-y;
            color: #FFFFFF;
        }
        .menu-vertical ul.root > li > a
        {
            background-color: #E7DBEF;
            color:    black;
            border-bottom: 1px solid black;
            font-weight: 600;
            text-decoration: none;   
        }
      • add custom background to top menu:
        .s4-tn

        {
            background-image: url("/SiteAssets/top_nav_bg.png");
            background-position: right top;
            background-repeat: repeat-x;
            color: #FFFFFF;
        }
      • add custom color to top menu selected item. Let's use Dark Orange - like LA Lakers ;)
        .s4-toplinks .s4-tn a.selected {
            background-color:#FF9E10;
            color:#09111D;
        }
      • transform all top menu items to be uppercase:
        .s4-tn .menu-item-text
        {
            text-transform: uppercase;
            font-size: 11px;
        }


    6. use custom larger logo that is transparent, so we can see the fading of the background.
    After applying these custom CSS classes we managed to create this (all elements that have been changed are highlighted:



    Step 5:  Add some fancy content to the home page
    Last thing we should do is add some fancy content to the home page. In my case I used SpZab Frontpage Slideshow which is pretty cool slideshow that use SharePoint list for data source and JQuery to display the content.


    So I just added this slideshow to the home page, and pick up 3 random images from my PC and now the home page become interactive, with moving content and much better design from the standard OOB design.
    And here is the result:

     Few important advices:
    • If publishing is enabled do not forget to publish major version, otherwise only you will be able to see the changes.
    • Always create new master page and set the new .master as Default/Custom Master page. Do not update the default one: if something happen with your custom master, you can always revert it back to the default
    • Be careful when overwriting generic HTML elements (like BODY, FORM, INPUT, SELECT, UL. LI) in the custom CSS files. SharePoint is calculating the size of the elements  dynamically and if you override some important html elementa, you might easily break the page design
    • Additional tools and files used to prepare this demonstration: 
      • FireBug add-on by Firefox  (to capture the CSS of rendered page)
      • ColorCop - small, lightweight and really cool application to capture some colors (also automatically copy the selected color, so you no need to press Ctrl+C)
      • paint.net - really nice: small, powerful and.... FREE program for image editing based 
      • FastStone Photo Resizer - I am always using it for mass updating/resizing of images. A must for every web designer
      • DESIGN MATERIALS used in the presentation: DOWNLOAD HERE

      Sunday, October 10, 2010

      Move ribbon row above the menu and below the logo

      Ribbon - to like or not to like?

      During my meetings with the clients, I've been asked numerous times the same question "Can you move the ribbon above the menu?" Personally I like it more this way as the SharePoint site looks like normal web sites that we see all the time: header that contains logo, slogan and some more stuff and then the top menu.

      Here is how standard Team site looks like, especially the ribbon that is on the very top of the page:

      Before customizing the master page, let's enable the publishing infrastructure - this way every change of the master page will require approval before actually appears on the site. This approach also minimize the risk of breaking the site by saving broken master page. Let's show it in steps:

      Step 1 - First of all let's activate the "Server Publishing Infrastructure" for Site Collections

         1. From the site, go to Site Actions and select Site Settings
         2. Under Site Collection Administration and chose Site Collection Features
         3. Activate the SharePoint Server Publishing Infrastructure

      Step 2 - next we need to  activate "Server Publishing" for the Site

         1. From the site, go to Site Actions and select Site Settings
         2. Under Site Actions chose Manage Site Features
         3. Activate the SharePoint Server Publishing

      Step 3 - edit the master page in SharePoint Designer

      1. From the site, go to Site Actions and select "Edit in SharePoint Designer"
      2. After SharePoint Designer is loaded, open the "Master Pages" in the left menu

        Next 3 steps will create new master page (I always recommend new master page rather then customizing the default one).
      3. From the Top Ribbon click the button "Blank Master Page" and enter some name
      4. Right click on the new master page and select "Edit File in Advanced Mode"
      5. Copy and Paste the HTML from the default v4.master
      By default the HTML for Ribbon is on the top of the master page after the start body tag:

       Now let's move the ribbon. actually we are going to move the row that contains  the Logo of the site and the short description: it will be a bit easier as it contains less HTML then the ribbon.

      1. So find the following code in the source: <div class="s4-title s4-lp"> and simply right click and select the option "Select Tag":
      2. Cut the whole HTML that is selected
      3. Paste the HTML above the ribbon row which is
        <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle">Also shown below where to paste the HTML: 
      After doing this simple step we managed to get this:



       Here are few more examples how this small change affect the whole look&feel of the site: