Category Archives: Sharepoint 2010

Powershell – change masterpage for your SharePoint site

This will work on both 2007 and 2010 version

 

 

$Host_URL = "http://portal"
$web = Get-SPWeb $Host_URL

if ($web.ServerRelativeUrl -eq "/")
{
$web.CustomMasterUrl =  "/_catalogs/masterpage/horsik.master"
$web.MasterUrl =  "/_catalogs/masterpage/horsik.master"
}
else
{
$web.CustomMasterUrl = $web.ServerRelativeUrl+ "/_catalogs/masterpage/horsik.master"
$web.MasterUrl = $web.ServerRelativeUrl+ "/_catalogs/masterpage/horsik.master"
}
$web.Update()

SharePoint 2010 Add rating stars to Content By Query WebPart xsl style (CQWP)

There is a good post about it at http://geeksthenewblack.wordpress.com/2010/10/29/show-rating-stars-in-the-content-query-web-part/ and that is how I started.

But there is a gap. You need to do two additional steps to display stars in your Content Query WebPart.

STEP 1:

Export WebPart and edit  it in Editor. I spent lots of time finding what column and column type I need. I was trying Decimal, Number, it did not work. Finally I looked for AverageRating column in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML\fldtypes_SPRatings.xml – there is actually field type : AverageRating

<property name=”CommonViewFields” type=”string”>AverageRating,AverageRating;</property>

STEP 2:

Import your modified webpart file and edit it, you need to look at slots, under Presentation > Fields to display, assuming you used xsl style from mentioned blog post, you should have Ratings slot there, you need to map it to Rating (0-5);

When you save your webpart, it should include stars:

Don’t be surprised if you don’t see stars straight away. You should first make sure that your pages have rating. If you just rated them minute ago, rate calculation may not finish yet, it runs every hour on the server. Go to the page ans see if you see rating. In my case, I have Enterprise Wiki pages but you can rate any content in SharePoint 2010. To speed up the process, if you have access to your Server Central Administration, you could trigger rating calculation.

Ratings works with the help of the two timer jobs :

  • User Profile Service – Social Data Maintenance Job
  • User Profile Service – Social Rating Synchronization Job

These two timer jobs are responsible for synchronizing rating values between the Social Database and the Content Database. By default it’s configured on hourly interval. Change the interval to desired minutes will allow the timer job run more frequently and synchronize the rating data quickly. You can also trigger this jobs to run immediately for testing purposes

SharePoint 2010 themes – all you need to know about customisation

In this post I will write about:

  • Out of the box themes overview
  • How SharePoint 2010 themes work
  • Theming core4.css and v4.master and why it is never enough
  • How to create your own theme-able css and package in WSP solution
  • Css 3 gradient backgrounds workaround

Themes in SharePoint 2007 are utterly dull and useless so I am not going to waste time to compare them with newer and better engine that we find in SharePoint 2010. Out of the box, every SharePoint site comes with about 15 predefined themes that you can find by going to Site actions > Site settings > Theme. You can apply theme on both site and web level. You can apply theme to the site and inherit the setting to all site subsites. New interface also allows you to modify theme on the fly. By changing 12 theme variables (tokens) you have limitless variations to color your site. This way usually only makes it uglier but feel free to try- why not to make your site look like a vomit 🙂 You can also create a new theme using PowerPoint 2010, good news is that it comes with the same engine, so, theoretically, if you have nice company presentation template you could quickly apply similar look and feel to your SharePoint site. Moreover, you can save your new theme to theme gallery and make it available for other sites. To go to theme gallery, go to site collection settings (every site collection has separate theme gallery), theme gallery will be always available at this address http://yoursiteURL/_catalogs/theme/Forms/AllItems.aspx  You can upload your .thmx file there. This way, you can control what colors and fonts your site has, but you cannot control how they are used. Also, you will not really know the site will look until you actually apply your theme. E.g. you changed Light2 color to be BLUE, after you apply this change, you will find out, that left navigation, some of header, and some text will be colored with this color, some other components on the page can have slight ligher tone, some will appear as darker blue. This is because of the fact, that every color you choose can be used by someone who creates CSS style-sheet file in many different ways. E.g. someone decided that Light2 color will be used as navigation background, but for active navigation item – background will be Light2-Lightest – this tells SharePoint to use lighter tone of this color. Colors you choose are also used to color images for gradient effects (site header, navigation bars). It is very easy to come up with rainbow like sites when you are not careful. To understand how it works it is the easiest to look at out-of-the-box css that is used for SharePoint collaboration sites (most commonly seen sites). This file sits on the server under C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\STYLES\Themable and C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\STYLES.  Yes, there are two files which are exactly the same but sit on different locations. This is location where you can deploy your custom css, because this is one of possible places SharePoint allows to store themable css files (other one is Style Library) First, let’s focus on file content, below a few fragments:

 .ms-toolbar{
font-family:verdana;
font-size:8pt;
text-decoration:none;
/* [ReplaceColor(themeColor:"Hyperlink")] */ color:#0072BC;
}

This styles tells SharePoint to use Hyperlink theme color to paint in toolbar.

body #s4-ribboncont{
padding:0px;
/* [RecolorImage(themeColor:"Dark2-Darker",includeRectangle:{x:0,y:589,width:1,height:20})] */ background:url("/_layouts/images/bgximg.png") repeat-x -0px -565px;
}

This style paints ribbon with a slightly darker from Dark2 color, and it is not just a color, it is coloring the image.

.ms-dlgTitle
{
/* [RecolorImage(themeColor:"Light2",includeRectangle:{x:0,y:51,width:1,height:21})] */ background:url("/_layouts/images/bgximg.png") repeat-x -0px -51px;
/* [ReplaceColor(themeColor:"Dark2",themeShade:"0.90")] */ background-color:#21374c;
height:32px;
white-space:nowrap;
cursor:default;
overflow:hidden;
}

So we have special comments in css file that will tell SharePoint how to modify css after theme is applied. /* [WhatToDo(use what theme token and how) ] */ before the style

.ms-WPBody a:link
{
/* [ReplaceColor(themeColor:"Hyperlink")] */ color:#0072bc;
text-decoration:none;
}
.ms-WPBody a:visited{
/* [ReplaceColor(themeColor:"FollowedHyperlink")] */ color:#b10069;
text-decoration:none;
}

So, when there is no theme applied, all links in webparts will have this color: #0072bc. When the theme is applied, SharePoint will derive completely new css file when it will replace all default colors with theme colors. The output css will be like below (fragment)

.ms-WPBody a:link
{
color:<span style="color: #123456;">#123456;</span>
text-decoration:none;
}
.ms-WPBody a:visited{
color:<span style="color: #654321;">#654321;</span>
text-decoration:none;
}

Important to note that SharePoint generate this new css once, when the theme is applied. It will store it in a special folder with a special unique name. SharePoint masterpage will automatically reference this css. E.g. /_themes/20/corev4-7B0CDD7F.css?ctag=21 Implication to this behavior is that once you set the theme for a site, any changes to original css will not take any affect. Of course you are not going to modify core css, but this fact will be important when you plan for your custom css you deploy and then maintain. Imagine scenario that you have to upgrade your css  (e.g. you need to change left menu width) – you will need to ensure that themed sites are reprocessed again (which means you would have to identify which sites are themed). If you think this gets a bit tricky,  you should consider creating multiple css files for your branding: one for layouts alignment (things that should never change) and one for themable elements. This way you have nice separation and control what is and what is not themed. With themes you have a few levels of customization possible, starting from the simplest and least flexible one:

METHOD 1.

No css/html skills required.  –  Create thmx file and upload to your site, if your site is using out of the box masterpage and css – this will work and you see the effect once theme is applied. Once you try this method, you will quicly run into obvious limitation. You can control what colors and fonts your site has, but you cannot control howthey are used. Below are some example of playing with themes, just to show you the idea:

All tokens white, black links, Accent1 - RED

All tokens white, black links, Accent1 - RED

Accent1-red, Links - Black, TextBackground 1 - yellow, Other - White

Accent1-red, Links - Black, TextBackground 1 - yellow, Other - White

Accent1-red, Links - Black, TextBackground 1 - yellow, TextBackground2 - Blue, Other - White

Accent1-red, Links - Black, TextBackground 1 - yellow, TextBackground2 - Blue, Other - White

Accent1-red, Links - Black, TextBackground 1 - yellow, TextBackground2 - Blue, TB3 - Black, Other - White

Accent1-red, Links - Black, TextBackground 1 - yellow, TextBackground2 - Blue, TB3 - Black, Other - White

Accent1-red, Links - Black, TextBackground 1 - yellow, TextBackground2 - Blue, TB3 - Black,TB4 - Green, Other - White

Accent1-red, Links - Black, TextBackground 1 - yellow, TextBackground2 - Blue, TB3 - Black,TB4 - Green, Other - White

Accents in edit mode

Accents in edit mode

Sharepoint 2010 Font theming

Sharepoint 2010 Font theming

METHOD 2.

Some css/html skills required, no Visual Studio. Use SharePoint Designer. Create a new css file (in Style Library), copy all core4.css content to it (or not, if you decide to still reference corev4.css, you can start from empty new css and only copy styles as you go). Use Firebug to identify lines of css you need to change. Copy them to your custom.css  and modify to your taste. Register your css in masterpage.

<SharePoint:CssRegistration name=”<% $SPUrl:~sitecollection/Style Library/~language/ Themable /custom.css %>After=”corev4.css”runat=”server”/>

This method is sufficient when you need to change some default behavior. E.g. If you don’t want left navigation background to be the same as top navigation background. Also, it is only way if you are not allowed to deploy anything to the server. Assuming you are customizing v4.master and core4.css, this will give you very limitless flexibility in terms of changing things on your SharePoint site. You usually start from css changes but you will quickly find it hard to not to touch masterpage as well. E.g. to modify top navigation or breadcrumb behavior, or to add “People search box”.

METHOD 3.

Use Visual Studio 2010 to package your custom branding components. When working with deeper branding files you have to deploy are:

  • images (icons, gradients, logos, headers etc.) – after some time of working on SharePoint branding I find /_Layouts/IMAGES/customfolder/ folder the best place for them. Mostly because of easier referencing them in masterpage and css (always same path that does not depend on whether this is the site on managed path or on root server level)
  • masterpage (one or more) – this gets deployed to masterpage gallery through module
  • page layouts (you can sometimes leave without them) – these get deployed to masterpage gallery through module
  • css files – I was usually happily deploying these to Style library, for themable css under /locale/themable/customfolder/custom.css. But I have recently got the case when I needed to reconsider and to deploy to \TEMPLATE\LAYOUTS\1033\STYLE. This was because in my css I had some gradient coloring using newer techniques like:
/* For Firefox 3.6+ */ background: -moz-linear-gradient /* For WebKit (Safari, Chrome, etc.) */ background: -webkit-gradient .../* for Internet Explorer */
filter:progid:DXImageTransform.Microsoft.gradient( ...

Because there are multiple colors in one line and it is all in function, to theme it you would need to do something intense like this:
background: -webkit-gradient(linear, left top, left bottom, from(/* [ReplaceColor(themeColor:"Light2-Lightest")] */ #FEFEFB), to(/* [ReplaceColor(themeColor:"Light2-Lighter")] */ #E9E9E9));

Surprisingly, theme engine was quite happy to process these lines of css, but css file was corrupted when theme was not applied and gradient was not working. So I had to use the trick of having one custom.css file at LAYOUTS\1033\STYLES\custom.css and another one at LAYOUTS\1033\STYLES\Themable\custom.css.  In first one, I didnt have any tokens, in themable one, I had tokens. Then in my masterpage, I referenced my custom.css as:


  <SharePoint:CssRegistration ID="anmm_portal" name="custom.css" EnableCssTheming="true" After="corev4.css" runat="server"/>

This way - when no theme is used LAYOUTS\1033\STYLES\custom.css is used. When theme is applied, same named file from Themable folder is taken. I figured it out thanks to this post: http://stackoverflow.com/questions/4900215/can-ms-filter-styles-be-themeable-in-sharepoint/

  • js files
  • jQuery framework ( a must for web developers)
  • Themes variations that will work with your masterpage and css. You can deploy color variations as a module
<!--?xml version="1.0" encoding="utf-8"?--><?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="MOThemes" Url="_catalogs/theme" Path="MOThemes" RootWebOnly="true">
<File Url="Blue.thmx" Type="GhostableInLibrary" Path="Blue.thmx">
</File>
<File Path="Red.thmx" Url="Red.thmx" Type="GhostableInLibrary" />
</Module>
</Elements>

SharePoint 2010 Service Pack 1 released !!!

SharePoint 2010 Service pack 1 is now available and can be downloaded from the links here.

Make sure that you install the June cumulative update AFTER installing the service pack to bring it up to the latest and smoothest version.

It would also be advisable to use the SP1 planning worksheet here to assist in the rollout of the new release.

Good luck all with the updates !

 

Link site logo to Site Collection URL

When working with SharePoint masterpages knowing available tokenscomes really handy. E.g. Standard masterpage will have a logo image that will always link to default page of current site. Usually, you want to link logo to top level site.

This logo is linked to current site. E.g. http://server/sites/test/subsite

<SharePoint:SPLinkButton runat=”server” NavigateUrl=”~site/” id=”onetidProjectPropertyTitleGraphic” >
<SharePoint:SiteLogoImage name=”onetidHeadbnnr0″ id=”onetidHeadbnnr2″ LogoImageUrl=”/_layouts/images/siteIcon.png” runat=”server”/>
</SharePoint:SPLinkButton>

This logo is linked to root site. E.g. http://server/sites/test/

<SharePoint:SPLinkButton runat=”server” NavigateUrl=”~sitecollection/” id=”onetidProjectPropertyTitleGraphic” >
<SharePoint:SiteLogoImage name=”onetidHeadbnnr0″ id=”onetidHeadbnnr2″ LogoImageUrl=”/_layouts/images/siteIcon.png” runat=”server”/>
</SharePoint:SPLinkButton>

ONET.xml – Provisioning did not succeed. Details: Failed to initialize some site properties for Web

If you use Visual Studio to create new Web Templates you sometimes get this error when testing your work:

Provisioning did not succeed. Details: Failed to initialize some site properties for Web at Url: ‘http://server/sites/test&#8217; OriginalException: <nativehr>0x80070002</nativehr><nativestack></nativestack>

To diagnose this error, go straight to ULS logs that usually sit under C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

Look for your site URL at the bottom of the file, if you recently have got that error. Don’t bother looking by correlation guid, notepad search will not find it for some reason.

You should see more details why your site has not been created.

E.g. you will find that provisioning process actually checks some files existance. You will find:

GetFileFromUrl: FileNotFoundException when attempting get file Url http://server/sites/test/_catalogs/masterpage/MyCustomLayout.aspx<nativehr>0x80070002</nativehr><nativestack></nativestack>

You must ensure that this file is in the library when this feature is activated.

This is onet.xml fragment that you should be careful with.

 <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
          <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
            <Property Key="WelcomePageUrl" 
         Value="$Resources:osrvcore,List_Pages_UrlName;/Home.aspx" />
            <Property Key="SimplePublishing" Value="True" />
            <Property Key="VersioningOnPages" Value="Major" />
            <Property Key="RequireCheckoutOnPages" Value="False" />
            <!--added custom layout -->
            <Property Key="AvailablePageLayouts" 
       Value="~SiteCollection/_catalogs/masterpage/EnterpriseWiki.aspx
 :~SiteCollection/_catalogs/masterpage/RedirectPageLayout.aspx
 :~SiteCollection/_catalogs/masterpage/ProjectPage.aspx"/>
            <!-- custom default layout WikiWelcomePage-->
            <Property Key="DefaultPageLayout" 
Value="~SiteCollection/_catalogs/masterpage/MyCustomLayout.aspx"/>  
            <Property Key="AllowSpacesInNewPageName" Value="true"/>
          </Properties>
        </Feature>

Account deleted in AD causes Sharepoint 2010 crash – “The specified user or domain group was not found”

In one of my projects I have recently ran into interesting issue.

We have number of services configured and running without issues. All at once, one day, we cannot access Central Admin > Manage Service Applications page and our Performance Point service stopped working.

We get “The specified user or domain group was not found”.

In logs, I found:

SPAce PrincipalName XXX\user cannot be resolved. This ACE will not be effective. System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.     at System.Security.Principal.SecurityIdentifier.Translate(IdentityReferenceCollection sourceSids, Type targetType, Boolean forceSuccess)     at System.Security.Principal.SecurityIdentifier.Translate(Type targetType)     at Microsoft.SharePoint.Administration.SPAce`1.get_PrincipalName()

And yes, this AD user was recently removed from Active Directory,

To resolve the issue I found this post very usefull: http://architectevangelist.wordpress.com/2010/12/07/sharepoint-2010-the-specified-user-or-domain-group-was-not-found/

The only problem was that in my case running Get-SPServiceApplication was erroring, I could not figure which service is causing the problem.

Then I used this query

SELECT  [Name], [Version],CAST([Properties] asxml)as ‘xml2’ From  [sharepoint_configuration][dbo].[Objects] with (nolockwhere Properties like  ‘%user%’ 

This way, I found that this user is administrator of secure store service. But there is no way to remove him from being administrator if I cannot access service properties (because of this error)

So the only way is to bring back deleted account, then delete it from any service Administrators lists.

Move site collection to different database Move-SPSite

Handy command in Sharepoint 2010

Move-SPSite <SiteURL> -DestinationDatabase <DBName>

Before you execute this command be aware that:

1. this will put your site offline when running. Users will get error when browsing the site:

          The website declined to show this webpage (403)

2.You will have to perform IISRESET afterwards

3.But cheer up, command executes suprisinly quick when comparing with execution of Restore-SPSite. For 7 GB site it took only 5 minutes.



“Excel Services is unable to process the request. Wait a few minutes and try performing this operation again.”

On your Sharepoint 2010 site users are uploading Excel files. Excel 2003 files (xls) will work ok and will open in Excel when you click them. On the other hand – when you have xlsx file it will try to open in xls viewer inside your browser. In some circumstances (I will describe it in this post) it will fail. User will get an error:

“Excel Services is unable to process the request. Wait a few minutes and try performing this operation again.”

Investigation steps:

  1. Check if your excel services is running
  2. Check if your server have this hotfix installed : KB976462  – I had this installed but error was still there http://support.microsoft.com/default.aspx/kb/976462?p=1
  3. Myth busted – you dont need Office Web Apps installed to make it work – don’t bother installing it.
  4. Check if your web application has Excel service connection – this part was missing in my case. Go to Central Admin > Manage Webapplications. Click application that hosts your site collection. Click “Service Connections”. Check if your Excel Service Application is ticked. If not change connections from default to custom and tick this Service.

If, for some reason, you don’t want files to be open in browser but you want them to be always open in client application, you can do it in two ways:

1. All sites at once – this is tricky but you need to go to Central Administration > Site Settings > Site collection features and turn on this feature – “Open Documents in Client Application By Default”. Yes, feature for Central Admin site will influence every site in your farm (interesting…)

2. On document library level – you can go to Library Settings > Advanced settings and change “Default open behavior for browser-enabled documents” to “  – This will change behaviour only for this one document library

Console application in Visual Studio 2010 to access Sharepoint object model

You can experience some “beginners” troubles when you create your “test something in Sharepoint” first console application with new Visual Studio 2010. You will not be able to build project unless you do some changes:

After you added Reference to Microsoft.Sharepoint.dll (which you will find only by browsing to c:\program files\common files\microsoft shared\web server extensions\14\isapi) you can start programming with Sharepoint API but when you try to run your app, you will get compilation error.

To solve it:

Right click project, select Properties.

On first section (Application) change target framework  – .Net Framework from 4.0 to 3.5.

Under Build section change Target platform to 64 bit.

Now, try to run your app again.