Posts

Use XSLT to hide columns in SharePoint list forms

Image
In this post i will explain how XSLT can be used to hide the list columns in forms for users with insufficient previleges. After you open your site and the list in SharePoint designer, create custom forms for New, Edit and Display forms. Open each of the forms and select the column which should be shown based on user permissions. Expand the Conditional Formatting option on the ribbon and select Show Content. In the next screen click on Advanced. In the pop up that appears after that, search for the function called IfHasRights This function will determine whether the current user has the rights specified and will do the formatting accordingly, based on the result. The permission mask specified is determined as the sum of the permission masks for the permissions required. Below mentioned are the permission masks for the permissions. ViewListItems - 1 AddListItems - 2 EditListItems - 4 DeleteListItems - 8 ApproveItems - 16 OpenItems - 32 ViewVersions - 6...

SharePoint list forms display HTML instead of rendering

Image
I have recently come across a problem where a custom list form i created using SharePoint designer was displaying the HTML directly instead of rendering it. As shown above the HTML for the Assigned To column value is not being rendered. To overcome this you just have to add a simple property to you XSLT. Select the HTML that is displayed and go to the code view. You will see the statement as <xsl:value-of select="@Assigned TO"></xsl:value-of> To this you have to add a parameter called display-output-escaping <xsl:value-of select="@Assigned TO" display-output-escaping="yes"></xsl:value-of> As you can see, this time the HTML is rendered properly.

Unable to load assembly group - Sandbox solution

I ran into an error lately when i tried to add a web part which i created as a Sandbox Solution. It said Unable to load assembly group. The user assembly group provider threw an exception while trying to provide user assemblies for the specified assembly group To resolve it follow the below steps 1. Go to services.msc 2. Check the service account for "SharePoint 2010 User Code Host service" 3. Change it to a domain account or probably to the farm account.

URL fields in SharePoint Content Query Web Part

Image
When a content query web part is used to query and display the items in the Links list, i got the output in a very undesirable format. As you can see in the image above, it is showing the URL of the link followed by a comma and then the link text. Also when you click on the link in will take you to the display form for that item in the links list instead of taking us directly to the URL of the link. So i started to modify the XSL to get the desired bahaviour which is It should show only the link text without the URL The hyperlink should point to the URL rather that the display form for that item. For this go to your site's Style Lirrary->XSL Style Sheets Download a copy of the ItemStyle.xsl I named the copy as CategoryItemStyle.xsl. Modify the content of it to this Upload the CategoryItemStyle.xsl to the Style library-> XSL Style Sheets. Then export the default the Content Query Web Part and open in it in notepad or Visual Studio Change the ItemXslLink ...

Remove hyperlink for lookup columns in SharePoint

Image
I tried to look for how to remove the hyperlink for the lookup columns in SharePoint. I was expecting some kind of an XSL transformation. But all the posts i found in the internet were using JavaScript for this functionality.  So i decided to work on the XSLT myself. I know this is a much cleaner and efficient solution. And this is how it is done. I have a list with a lookup column called "DeptLookup". To remove the hyperlink follow the below mentioned steps Open this list in SharePoint designer. Click on the AllItems.aspx to open it. Select the lookup column Click on the formula on the ribbon This will open a dialog for you called Insert formula The default formula for the lookup column is $thisNode/@*[name()=current()/@Name] Change it to substring-before(substring-after($thisNode/@*[name()=current()/@Name],'>'),'<') Click on OK and save the changes. Now when you go to the list, you will see the lookup values without the hype...

SharePoint Edit Page and Personalize page using Javascript

I had to dig deep to find out what are the javascript functions called when we click the Edit Page button the SharePoint ribbon. I had to hide the ribbon for one of my client's requirements and i had to provide links for Edit Page, Personalize page and Save page. I have used three hyperlinks for each of these functionalities. This is how we can do it in SharePoint. <a href="javascript:ChangeLayoutMode(false);">Edit</a> <a href="javascript:ChangeLayoutMode(true);">Personalize</a> <a href="javascript:ChangeLayoutMode(null,true);">Save</a> These functions are available in a Javascript file which SharePoint includes by default. So you just have to place this html on your page and there you go.

Config file for SharePoint custom timer jobs

Image
SharePoint timer jobs run under the OWSTIMER.exe process. This process has a configuration file associated with it. We can use this config file to specify the configuration settings that are to be used in custom timer jobs. Open the OWSTIMER.EXE.CONFIG and add the <appSettings> tag to it. Then add your key value pairs under this appSettings tag For this you have to add a reference to System.Configuration Then you can use the  System.Configuration. ConfigurationManager .AppSettings[ key ]  to retrieve the values for a key from the config file. Example:  string dept = System.Configuration. ConfigurationManager .AppSettings[ "Department" ];