Wednesday, April 29, 2015

QuickTip: Display multiple values based on selection in InfoPath

I have a form with a selection box where the user selects a Role, and based on that Role I set a multiselect field with the predefined values, in this case Applications. What I wanted to do, was to have the checkboxes selected by default OR not display the checkboxes at all. Because this should be a list of all applications that are included when you select a specific role, so the user should not be able to check or uncheck any boxes. I select a role in the left drop down box, and all the values are shown to the right in a Multiselect box:


It does not seem possible to have all values selected in the Multiselect field, only the top value can be selected and that is not what I want. It's either ALL values or NO checkboxes. Well simple enough I chose the "ListBox" instead, that rolls up all values without checkboxes. The only downside is that you can select one or more values but I have not published the values in the fields anywhere and I am not saving them so it is fine. So the left drop down box selects a role and the listbox shows all values separated by a new line:




Display comments and likes in CQWP

This is an update from my former blog post about showing likes and comments in a news web part. And I also get questions about how I have done this, and people saying that they never managed to do the same. So even if I updated the former blog post with this solution, it may not have been clear enough how I did it.

First of all, I changed from using the CSWP (Content Search Web Part) to use the CQWP (Content Query Web Part) as I never got the Comments to work without always running a Full crawl (and we don't want that!).

Then I create the news on a separate Blog site. The news will then be rolled up on the intranet front page in the following format:


As shown in the picture above, the news item is rolled up displaying Published Date, Title, Likes and Comments. Sometimes I also add the Category, but that part is easy and if you can add one you can add another of these fields, so I will mostly focus on how I did the Like and Comments part.

To modify the CQWP you must first add your own xsl files.
NOTE: do NOT modify the existing files - they might get overwritten in an update OR you might write something totally wrong and nothing will work on your site. You always create a new folder called "Custom" (or whatever you want), then you COPY existing files and paste them into your folder and there you can modify them without taking a risk.

Easiest is to open your site in SharePoint Designer, browse to the folder Style Library > XSL Style sheets > Create your own folder "Custom". Then copy the file called "ItemStyle.xsl" and paste into this new folder.


Now go to the site where you first add the CQWP and then export that same web part. You export a web part by clicking the arrow on the web part and then select "Export":


Open the file, it might be called "News.webpart" or whatever you named the web part, and find the row with the property name "ItemXslLink" and change the path to the new that was created above:

Tag: property name="ItemXslLink" type="string"
New value: /Style Library/XSL Style Sheets/Custom/ItemStyle.xsl

It should look like this in the webpart file now:


Then add the fields that should be displayed in the web part, they need to be added in a special way and you must find out their GUID. Find the property tag called "DataMappingViewFields" and the fields must be added in this syntax: {GUID}, Type and then separated with ;


To find the GUID of the fields that should be displayed, go to the list where the columns are and hover each column or click on it and look in the address field. The URL will contain the GUID. Be sure to remove the ASCII for % and - since they are in the URL.
Example:
I want to get the field where Comments are, (which is a Lookup Field) so I go to my news blog and open the Posts list. Go to the List settings and scroll down to find the Column field. Click on it and copy the URL and then paste that into Notepad. You will get something like this:


Then in Notepad, copy only the GUID from the URL:

%7B6026020B%2D0EB4%2D42D0%2DAA51%2D2BBA3A3CD9DF%7D

And then replace all ascii characters with the normal character like

%7B which is {
%7D which is }
%2D which is -
and you will get

{6026020B-0EB4-42D0-AA51-2BBA3A3CD9DF}

Do this for all fields that you want to display in the web part, like Comments, Likes, Category etc

Before you upload the web part file, go back to SharePoint Designer and open the custom xsl file. Add a new xsl:template in the file like this (it is an image):



The entire code in this is here, but the < tags are exchanged to [] so that the code can be displayed here on the page (just replace the [] with the regular < tags):

[?xml version="1.0" encoding="utf-8" ?]

[xsl:stylesheet
  version="1.0"
  exclude-result-prefixes="x d xsl msxsl cmswrt"
  xmlns:x="http://www.w3.org/2001/XMLSchema"
  xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
  xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
    xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"]
[xsl:param name="ItemsHaveStreams"]
    [xsl:value-of select="'False'" /]
  [/xsl:param]
[xsl:variable name="OnClickTargetAttribute" select="string('javascript:this.target="_blank"')" /]
[xsl:variable name="ImageWidth" /]
[xsl:variable name="ImageHeight" /]

[xsl:template name="BigImage" match="Row[@Style='BigImage']" mode="itemstyle"]
[xsl:variable name="SafeImageUrl"]
            [xsl:call-template name="OuterTemplate.GetSafeStaticUrl"]
                [xsl:with-param name="UrlColumnName" select="'ImageUrl'"/]
            [/xsl:call-template]
        [/xsl:variable]
[xsl:variable name="SafeLinkUrl"]
            [xsl:call-template name="OuterTemplate.GetSafeLink"]
                [xsl:with-param name="UrlColumnName" select="'LinkUrl'"/]
            [/xsl:call-template]
        [/xsl:variable]
[xsl:variable name="DisplayTitle"]
            [xsl:call-template name="OuterTemplate.GetTitle"]
                [xsl:with-param name="Title" select="@Title"/]
                [xsl:with-param name="UrlColumnName" select="'LinkUrl'"/]
            [/xsl:call-template]
        [/xsl:variable]      
     
[div id="Item_LargePicture" style="padding-bottom:10px"]

        [div class="cbs-largePictureContainer" id="_#= containerId =#_" data-displaytemplate="ItemLargePicture"]
            [div class="cbs-largePictureImageContainer" id="_#= pictureContainerId =#_"]
                [xsl:if test="string-length($SafeImageUrl) = 0"]
[a href="{$SafeLinkUrl}"]
[img src="/_layouts/15/images/custom/emptynews.png" class="cbs-pictureImgLink" /]
[/a]
[/xsl:if]
[xsl:if test="string-length($SafeImageUrl) != 0"]
[a href="{$SafeLinkUrl}" class="cbs-pictureImgLink" ]
[xsl:if test="$ItemsHaveStreams = 'True'"]
[xsl:attribute name="onclick"]
                          [xsl:value-of select="@OnClickForWebRendering"/]
                        [/xsl:attribute]
[/xsl:if]
[xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'"]
[xsl:attribute name="onclick"]
                        [xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/]
                        [/xsl:attribute]
[/xsl:if]
[img src="{$SafeImageUrl}?RenditionID=5" title="{@ImageUrlAltText}" class="cbs-pictureImgLink" id=""/]
[/a]
[/xsl:if]

            [/div]
                     
            [div class="cbs-largePictureDataOverlay"  id="_#= dataContainerOverlayId =#_"][/div]
            [div class="cbs-largePictureDataContainer" id="_#= dataContainerId =#_"]
             
                [a class="cbs-largePictureLine1Link"]

[h2 class="cbs-largePictureLine1"]

[a href="{$SafeLinkUrl}" title="{@LinkToolTip}" class="cbs-largePictureLine1Link"]
[xsl:if test="$ItemsHaveStreams = 'True'"]
[xsl:attribute name="onclick"]
                  [xsl:value-of select="@OnClickForWebRendering"/]
                    [/xsl:attribute]
[/xsl:if]
[xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'"]
[xsl:attribute name="onclick"]
                      [xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/]
                    [/xsl:attribute]
[/xsl:if]
[xsl:value-of select="$DisplayTitle"/]
[/a][/h2]

[/a]
           
                [span title="_#= $htmlEncode(line4) =#_" id="_#= line4Id =#_" ]
                [xsl:value-of select="ddwrt:FormatDateTime(string(@PublishedDate) ,1053 ,'dd MMMM')"/][br /]
                [xsl:value-of select="@PostCategory"/][/span]
                [span title="_#= $htmlEncode(line5) =#_" id="_#= line5Id =#_"]
                [span style="padding-left:180px;"][xsl:if test="string-length(@LikesCount) = 0"] 0[/xsl:if]
[xsl:value-of select="@LikesCount" /][span style="padding-left:3px;vertical-align:text-bottom"][img src="/_layouts/15/images/custom/like.png" border="0" /][/span][/span][span style="padding-left:10px;"][xsl:value-of select="@NumComments" /][span style="padding-left:3px;vertical-align:text-bottom"][img src="/_layouts/15/images/custom/comment.png" border="0" /][/span]
[/span]
[/span]            

            [/div]
        [/div]
    [/div]      

[/xsl:template]
[/xsl:stylesheet]


Okey so now we have a style for the news items. But there still are some things more to do.

Enable Image Rendition and Blob Cache to make the images render in the correct size, like thumbnails.

First upload this new web part into the sites WebParts gallery (its better to do that than to just upload it straight into the page, and you can also give it a proper name and put it in its own folder so its visible in the gallery when you add a new web part)

Then go to the start page and add this new web part. You have to modify it to point out the news blog location, and to select the correct display for it. And to make other settings that you need, like how many items that should be shown, what sorting order you want, if you want to add any filters etc.

In the web part settings, also go down to the section where the fields are mapped. Then add the names of the columns that you want to display, like PublishedDate, Category, Likes etc and you will find that there are new placeholders for these as we added those in the webpart file:


Yes it is in Swedish, but if you are familiar with CQWP (which I really hope you are, since this is quite complex to setup) then you should recognize the fields I am talking about. So, type in the name of the fields you want to display and DONE. But what? No, you cannot find a field for Comments? How surprising ;) This is where we need to go to Central Administration on the server and a new Mapping property in the Search app.

Go to Central Admin, open the Search service app, click on the link "Search schema" in the left menu and there add a "New managed property":



Call it what you want, like "NumberOfComments". Then set it to be Searchable, Retrievable, and then scroll down to the mapping. Add a new mapping and find the field called "ows_NumComments" and then Save this. You MUST run a full crawl for this to apply.



Okey, that was it. Simple right?? :) :)

Tuesday, April 28, 2015

QuickTip: Enable Anonymous access in SharePoint 2013

When you want to publish a SharePoint site as a public website, you must enable anonymous access - otherwise the user will be prompted with a login. Note: This is for on premises servers and not the cloud/Office365.

Open Central Administration on your server. Go to the Application Management section and then click the “Manage web applications” link.

Select the web application where you have your public web site collection and then click the “Authentication providers” button available in the Ribbon. It will most likely show a "Default" link:



Click on the “Default” and then check the “Enable anonymous access” option and then Save.



Now open the site collection that will be used as public website and go to the Site Settings. Click on "People and Groups". In the ribbon there is a button for “Anonymous Access” that allows you to configure how anonymous users can access to the site.


Click the “Anonymous Access” button in the Ribbon and find three options, select the one that is suitable for your site. In this case I would check the "Entire Web Site" to give the users full anonymous access to the site.



Now when you go back to the “People and Groups” page, there should be a new group called “Anonymous users” available in the list and it shows what permission they have on the site.

To test the anonymous web site, make sure you are signed out of the browser you are testing in, and see if you can access the site withouth having to sign in.

 

Friday, March 27, 2015

Site Collection Administration permission lost - strange issue

Strange thing that happened to my account. I am Site Coll Admin on all web sites on an on prem server, but one day the "Site Collection Administrators" and "Site Collection Features" links were gone from two of the sites (in Swedish):





First thing I checked is in Central Administration and "Change Site Collection Administrators"
I was listed on all sites

Then I logged in as the farm administrator and could access the "Site Collection Administrator" link. One site was empty of accounts and the other had only one other account listed. Strange, since I have never changed these values.
I simply added back the accounts and on one of the sites it worked fine. But, on the other I got this message when I tried to add back my own account:

Parametern loginName får inte vara tom eller längre än 251 tecken
Translated:  The parameter loginName cannot be empty or bigger than 251 characters

Very strange, I have never seen this error before. But this made me remember that when I tried to add one of our AD groups, I got a message that the name was too long. So there is a limit on how long account or group names you can use in SharePoint. Somehow these entries must have been removed - in an update? Or when I ran the powershell command that clears the logon cache? I have no idea.

I tried a few times more, and then boom - the accounts just went through and now all three accounts were added.

I have no code running on the sites, the only customization is in my master page but no big at all. I have not made any changes in the web.config files on these two sites.

The only change I can think of is that the ASP.NET feature was installed by another administrator on the server, we will remove it again because it generates other errors in Event Viewer. Maybe something happened when that was installed.

Any ideas?




Change favicon in SharePoint 2013

This is a quick fix!
To change the icon that is displayed on the bookmark in a browser from the:

To something more sexy, then do the following:

Create a new folder in this location C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES
I named mine "Custom". This is always best practice, so that your changes wont be overwritten in any update.
Paste your new favicon file, dont forget to rename the file extension to .ico

Open your html version of the master page (if you have a custom)
Change the location inside the tag 



Thursday, March 26, 2015

The Current server is running low on memory

There is an error reported in Health Analyzer on my SharePoint 2013 server regarding the Distributed Cache "current server is running low on memory".
 
So, the Distributed cache uses 10% of the  total physical memory on the server. The Distributed Cache service uses half of that memory allocation for data storage (also known as cache size), and the other half of that memory allocation is used for memory management overhead. When the cached data grows, the Distributed Cache service uses the entire 10 percent of the allocated memory.  (Source: technet)
To check the existing memory allocation, run this command
Use-CacheCluster
Get-AFCacheHostConfiguration -ComputerName ComputerName -CachePort "22233"
 
There is 16 GB RAM on this server, so 819 MB is not enough. First stop the Distributed Cache Service in Services on server in CA
I first tried to update the size to what Technet recommended (7168 MB) but then I could not start the service again since I did not have enough free memory:
 
Instead, I updated the size to the double at 1600MB with this powershell cmd:
Update-SPDistributedCacheSize -CacheSizeInMB 1600
Then started the Distributed Cache service and the message in Health Analyzer disappeared.
 

SOLVED: "Open with explorer" disabled in IE11

[SOLUTION]
I found that this button was disabled because of this line in my Master Page - I am using Bootstrap theme from Codeplex and that comes with its own master page.
What I had to do was change this line in the header from:
 to (taken from Seattle master page)
And now, the button is enabled and working!
 
[PROBLEM]
I have an issue with Internet Explorer 11 and SharePoint 2013. The option "Open with explorer" is disabled, it works in IE10 but not IE11:


I have tried all possible solutions:
- added the site to Compatibility View settings
- added the site in Local intranet
- checked the add-ons
- checked that the local service WebClient was started
- I am running the 32-bit version
- the kb 2846960 is installed (http://support.microsoft.com/kb/2846960)
And obviously it is working in Internet Explorer 10. Maybe there is a new hotfix or something that needs to be installed, have googled this but not found any proper solution yet.