Tuesday, April 8, 2014

New blog on sharepointbabe.com

I have moved to Wordpress, my new blog site will be on:


Wednesday, March 26, 2014

Custom Display Template for Content Search

I am using the web part "Content Search" to display the news. But I would like to make some modifications to the Display template "Large" that I am using. First, I would like to change the arrows that is used for the paging control. Then the images should be wider and I want another managed property to be displayed in the rollup. To do this, I have to create a copy of the display templates and modify it in an HTML editor.

There are two types of display templates. One that is prefixed with "Control" that controls the layout of the entire web part, like paging controls and such. The other one is prefixed with "Item" and is used to control the items that are rolled up in the web part. These display templates are independent of each other, but since I want to change both the layout of the entire control and each item, then I need to make a copy of these both html files.

Map the following URL to a network drive: http://yourSPserver/_catalogs/masterpage

Then open folder Display Templates > Content Web Parts

Note: Only copy the Control and Item html files,  the .js files are created automatically!

I copied the control file Control_ListWithPaging.html and named it Custom_Control_ListPaging. And then I copied the item Item_LargePicture.html and named it Custom_Item_LargePicture.
Note: Refresh the folder and note that the .js files are created:

Modify the Custom_Control_ListPaging.html

Give the file a proper Title, in this case "Custom List with Paging":

It will be displayed with that Title in the web part drop down under Display Templates in the web part:

I want to change the Paging icons, because they don’t look very nice:

The css classes needs to be changed inside the Control template, and modify the classes as you wish and refer to it from the new Control template. Might not be the most sexy buttons, but at least they look a bit more like my color theme on the site:

Modify the Custom_Item_LargePicture.html

I want to make images wider and add another third line in the web part so that I can display another field and that has to be done in the Item files. Open the Custom_Item_LargePicture.html and make the following changes:

Change the Title tag to something useful, so that it is displayed correctly in the dropdown list in the web part (same as above with the Control).

In the head, modify the mso:ManagedPropertyMapping: copy this code:

"'Line 2'{Line 2}:'Description'"

Change it to the below code, you can refer to any managed property you like (in this case Description) but it does not really matter since you can change it in the web part anyway:

"'Line 3'{Line 3}:'Description'"

This will add another line in the Property Mappings so that you can display a third line with a managed property in the web part (see "Line 3" below):

Then scroll down to the remarked js code and add a new variable after "Line 2" and name it to “Line3”. That is in the following places in the code::

Then change the markup also, add a new div:

I had to modify the css classes (by adding them to my own css stylesheet so they override the default ones) too to make the rows more aligned, since I added a third line. The result is:

Tuesday, March 25, 2014

Image Rendition and Blob Cache

I want to display my news in the Content Search Web Part. And use the one that displays 3 pictures on top and the text below them. But there are a few things I would like to change. One thing is to change the image size so that it fills the text area and still keeps the image in small size. To do this, I have to work with Image Rendition.

Under "Look & Feel" in the site administration, there is a setting called "Image Rendition". When click on that, it tells you that the blob cache is not yet configured:

Configure Blob Cache on the server:

Change the web.config file which is found in the inetpub folder for your site (similar path like C:\inetpub\wwwroot\wss\VirtualDirectories\80)

NOTE: Make a copy of the web.config before edit!

Go to the line that begins with “blob cache location"
Change the location attribute to specify a directory that has enough space to accommodate the cache size, typically a D or E drive (not the system drive!)
The size is expressed in gigabytes (GB), and 10 GB is the default. Do not set it to lower than that.
"BlobCache location="D:\BlobCache" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" enabled="true"

Save the web.config file and the site will automatically recycle.

Now when you go back to “Image rendition” on the site, you can add a new item:

Give it a unique name, I just added the word “Custom” after and then set your own image sizes:

To see examples of how the rendition works, go to an Image library and select “Edit renditions” while hovering an image:

This will show how the image renders in the different ID’s:

Now I have to create a new Display Template for my Content Search Web part so that I can use this rendition, and that will be my next article.

Monday, December 9, 2013

Upgrade iLoveSharePoint Workflow actions for SPD to 2013

After test upgrading my Project Portal, I was not able to edit the custom workflow I had built in SPD using the iLoveSharePoint Workflow action from Codeplex (which is awesome btw).

I struggled a bit with this today but finally found the perfect solution if you want to upgrade this workflow action for SharePoint 2013. I use this workflow action to automate the creation of project sites at our company intranet and find it very useful.

So first start with adding and installing the wsp file again on the SP 2013 server:

Add-SPSolution d:\xxx.wsp (where ever you store the wsp file)
Install-SPSolution iLoveSharePoint.Workflow.Activities.wsp -GACDeployment -CompatibilityLevel {14, 15}

Then you need to also edit the web.config file (and I have had to do this for all my custom wsp files) and move this section:

into the "targetFx" section:

I did an IISRESET right after, and then made sure it got deployed in "Farm solutions" in CA.

When you open the workflow in SharePoint Designer 2010, this is what it should look like:

But when you open it in SPDF 2013 you will have to add back the custom actions, they are gone of course. So add back the custom actions, make sure the workflow looks like it should and publish it again to your site:

Monday, December 2, 2013

Unexpected error when changing the Top Navigation

When I had all the problems with our Replicator, and after it was finally solved, it started replicating the map and navigation structure. I desperately tried to stop the replication because I could see that it was altering my Top Navigation which I don't wanted. But the damage was already done, and I went into the Site Actions and Navigation and thought I just change it back. Nooooo. After replication had changed it and I tried to stop it something must have happened because I got this error message now:

"An unexpected error occured while manipulating the navigational structure of this Web"

So I could no longer change the Navigation, and all I wanted to do was to reorder it under "Global Navigation". Another important thing, I could change the navigation on subsites! But not on the top site in my site collection.

Googled the error and found that this had been resolved with April CU 2013. Upgraded to that, but it did NOT resolve my problem.

Went through the ULS logs and it reported:

"System.Data.SqlClient.SqlException: Cannot insert duplicate key row in object 'dbo.NavNodes' with unique index 'NavNodes_AltPK'. The duplicate key value is (25a584d5-0f03-4bb5-bdea-2e57030c7817, 4e340cbd-639b-4d6e-aa19-cdb73ac35a00, 1002, -7).  The statement has been terminated.     at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)     at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)     at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)     at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()     at System.Data.SqlClient.SqlDataReader.get_MetaData()     at System.Dat... 852bae04-377b-43d5-b8f5-f354a1eb54b2
10/01/2013 13:55:02.05* w3wp.exe (0x2C34)                        0x07A0 SharePoint Foundation          Database                       d0d6 High     ...a.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)     at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)     at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)     at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)     at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)     at Microsoft.SharePoint.Utilities.SqlSe... 852bae04-377b-43d5-b8f5-f354a1eb54b2
10/01/2013 13:55:02.05* w3wp.exe (0x2C34)                        0x07A0 SharePoint Foundation          Database                       d0d6 High     ...ssion.ExecuteReader(SqlCommand command, CommandBehavior behavior, SqlQueryData monitoringData, Boolean retryForDeadLock)     at Microsoft.SharePoint.SPSqlClient.ExecuteQueryInternal(Boolean retryfordeadlock)     at Microsoft.SharePoint.SPSqlClient.ExecuteQuery(Boolean retryfordeadlock) 852bae04-377b-43d5-b8f5-f354a1eb54b2
10/01/2013 13:55:02.05  w3wp.exe (0x2C34)                        0x07A0 SharePoint Foundation          Database                       8z23 Unexpected Unexpected query execution failure in navigation query, HResult -2146232060. Query text (if available): "BEGIN TRAN DECLARE @abort int SET @abort = 0 DECLARE @EidBase int,@EidHome int SET @EidBase = 0 SET @EidHome = NULL IF @abort = 0 BEGIN EXEC @abort = proc_NavStructAllocateEidBlockWebId @wssp0, @wssp1, @wssp2, @EidBase OUTPUT SELECT @wssp3 = @EidBase, @wssp4 = @abort END IF @abort = 0 BEGIN EXEC @abort = proc_NavStructMoveNode '25A584D5-0F03-4BB5-BDEA-2E57030C7817','4E340CBD-639B-4D6E-AA19-CDB73AC35A00',4945,1002,-2,N'20130928 16:17:25',@EidBase,@EidHome, @wssp5 OUTPUT SELECT @wssp6 = @abort END IF @abort = 0 BEGIN EXEC proc_NavStructLogChangesAndUpdateSiteChangedTime @wssp7, @wssp8, NULL END IF @abort <> 0 BEGIN ROLLBACK TRAN END ELSE BEGIN COMMIT TRAN END IF @abort = 0  BEGIN EXEC pro... 852bae04-377b-43d5-b8f5-f354a1eb54b2
10/01/2013 13:55:02.05* w3wp.exe (0x2C34)                        0x07A0 SharePoint Foundation          Database                       8z23 Unexpected ...c_UpdateDiskUsed '25A584D5-0F03-4BB5-BDEA-2E57030C7817' END " 852bae04-377b-43d5-b8f5-f354a1eb54b2
10/01/2013 13:55:02.05  w3wp.exe (0x2C34)                        0x07A0 SharePoint Foundation          General                        8kh7 High     An unexpected error occured while manipulating the navigational structure of this Web. 852bae04-377b-43d5-b8f5-f354a1eb54b2"

So values that the top navigation is using, are duplicated in a table called "dbo.NavNodes" in the content db. Or are invalid somehow.
I opened the dbo.NavNodes db and copied all lines in it, to find that duplicate key "(25a584d5-0f03-4bb5-bdea-2e57030c7817, 4e340cbd-639b-4d6e-aa19-cdb73ac35a00, 1002, -7)" and it was just a page on the site, checked in and published. Cannot really see how this page would mess all up, it has been there for quite a long time also.

I found an article that suggested to run a SQL query on the content db, to find the duplicates:

SELECTTOP(20)Count(nav.Eid)AS 'DuplicateCount', nav.DocId, ad.Dirname, ad.Leafname FROM NavNodesAS nav with(nolock)INNER JOIN AllDocsAS ad with(nolock)ON nav.Docid = ad.Id WHERE nav.EidParent= 1025 AND DocID IS NOT NULLGROUP BY nav.DocId, ad.DirName, ad.LeafNameORDER BY 'DuplicateCount' DESC

And the result was:
So I knew that some nodes were corrupt, and finally I found a useful article that really helped solving my problem. I ran this command a few times and carefully testing the Navigation between each, (go to Site Actions and Navigation and try to change the order in the Global Navigation). I had to run the script that deletes the nodes a couple of times (three):

Open PowerShell on the server, check the size of those objects at the top level:

$siteUrl = "http://server"
$spWeb = Get-SPWeb $siteUrl
$spWeb.Navigation.QuickLaunch | ft Title
$spWeb.Navigation.TopNavigationBar | ft Title
Then delete the QuickLaunch Nodes using this cmd:

$siteUrl = "http://server"
$spWeb = Get-SPWeb $siteUrl
    Foreach($node in ($spWeb.Navigation.QuickLaunch))
    write-host "The node title is "$node.Title

Then delete the TopNavigationBar Nodes:

$siteUrl = "http://server"
$spWeb = Get-SPWeb $siteUrl
    Foreach($node in ($spWeb.Navigation.TopNavigationBar))
    write-host "The node title is "$node.Title

First when you run these commands you will get an error message: "Cannot complete this action" and just continue until that goes away:

You know when you should stop because then you don't get a red error message any longer:

Now I went into the Site Actions > Navigation again on my site collection and now I could change the order and save.

Monday, October 21, 2013

Setup an app store in SharePoint

If you want to create your own SP app store, then you need to go through quite a few steps..
Here we go!

In Central Admin

First create a new app catalog site

I created one on http://server:2013/sites/apps  
Create the app mgmt service application and the Subscription service app

Create the subscription service app

$account = Get-SPManagedAccount domain\account

$appPool = New-SPServiceApplicationPool -Name SubscriptionServiceAppPool -Account $account

$serviceApp = New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPool -name "Subscription Settings Service Application" -DatabaseName "SubscriptionSettingsDB"

$serviceAppProxy = New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication $serviceApp
Then make sure the services are started, both for App Management and for Subscriptions
Then stop the Timer service
Restart the WWW service
Start the Timer service

Create an alias on your DNS (or use whatever apps domain you want), like apps.yourserver.com
Add that URL in the Configure Apps URL in CA and the prefix you wish to use (I chose "apps")

On your site
Make sure Publishing site collection features are activated
When you choose "Add an app" and click on "From your organization", any apps you have added should be visible now:


Wednesday, September 11, 2013

Search hangs on "Starting"

I think I know why this happened from the beginning. I got the warning message in Health Reports about having Admin accounts running the app pools or services. So I have corrected one account and now all these messages are gone. But that caused a new problem with Search Service. The error message was:

"Unable to retrieve topology component health states. This may be because the admin component is not up and running."
Googled it, and found lots of articles about this error. Most suggestions was about installing hotfixes, adding permissions directly in the SQL db's, changing environment variables, installing latest win updates etc etc.

But I had a feeling it had more to do with the accounts running the Search services or application pools. I had changed some of these from farm account to a specific service account, for security reasons and what MS recommends. But, after having changed back the SharePoint Search Host Controller to the farm account, (Go to "Security", "Configure service accounts" and select the "Windows Service - Search Host Controller Service", make an IISRESET afterwards) and all started working instantly.

Maybe not recommended, but I will keep it running like this. The message in the Health Analyzer has not come back so, so far so good.