SharePoint permission configuration is one of the hardest things for end-users to understand. Sometimes it is easier to explain a specific scenario instead of how the entire permissions concept works.
I did a video/podcast with Modermodemet last week, concerning personal productivity (note: English and Swedish). It was a fun chat that covered your own personal assistant (Jarvis?) to how to manage multiple calendars.
During the conversation, I mentioned two things that seemed to make an impact:
- I include travel time in my agenda.
Especially when you travel to multiple locations, having this time booked means you have a much better chance of not being double booked.
- My travel time automatically gets a special color (conditional formatting in Outlook)
This is a very simple example from my calendar:
I am running Outlook 2013 in this example, but I have been using this since Outlook 2007 or so. I know it got a little bit more complicated in Outlook 2010, so here’s an example for configuring appointments with “travel” in the subject to be a specific color.
- When viewing the calendar, go to the view tab in the ribbon and click on “View settings”:
- Click on “Conditional formatting…”
- In this dialog, you manage the conditional formatting rules. Click “Add” to create a new rule. In this same screen, add the type and choose the color. Finally, click “Condition…” to configure.
- For this example, just fill in “travel” in the subject. The conditions can become far more complex if you want to.
- Click “OK” to finalize all changes and return to the calendar view. My travel appointments are now the blue color I configured them to be automatically:
During the discussion, I also mentioned that my partner and I generally don’t share a calendar. For example, if we have a work obligation in the evening, we create an event and label it with either “H: event title” if it is me, or “F: event title” if it is him. Then we invite the other person to it. In my calendar, anything that starts with “F:” automatically is turned red so I know it is an appointment for my partner. It’s a very similar idea to the conditional formatting for the travel time.
This is such an easy thing to configure and the automatic colors make it so much easier for me to see what’s in my calendar at a glance.
Note: this post is written specifically for SharePoint 2013.
Sometimes it is necessary to add a snippet of code to just one page. Examples could be:
- Alternative CSS for just that page, i.e. to style a specific element
- Add a piece of CSS to hide the left navigation on specific pages
- Add the Open In Explorer Link to a page
There are technically a number of ways to achieve this:
- Paste the code directly into the page contents (does not work)
- Paste the code into the the HTML source of the Content Editor Web Part (can work, depending on SP version and code)
- Use the Embed command (can work, situational)
- Save the code in a text file, save it somewhere on your SharePoint site collection and call the text file via the Content Editor Webpart (my preferred method)
Option #4 is my favorite for a number of good reasons:
- You can save the code centrally and then call it from multiple places without needing to replicate it
- By saving it centrally, you only need to update it once if there are changes or updates
- By saving it in the content database, you can access it from SharePoint Designer or similar, meaning you do not need to keep downloading-updating-uploading
- It works consistently across all versions of SharePoint from SharePoint 2007 up to Office 365
<p>All right reserved © <script> var cur = 2010; var year = new Date(); if(cur == year.getFullYear()) year = year.getFullYear(); else year = cur + ' - ' + year.getFullYear(); document.write(year); </script> </p>
Option 1: Paste the code directly into the page content
You can paste the code directly into the page content.
However, once you save the page and view it, you will see that SharePoint does not realize that it is code it needs to render in some way.
Conclusion: do not place code directly in the page content as it does not work.
Option 2: Edit source in rich text area / CEWP
In most content editor webparts and all rich text areas, there is a button in the ribbon called “Edit source”. This is great for quick fixes when content has gotten out of hand. In older versions of SharePoint, you could also use it to embed extra code.
You can easily paste your code straight into the Edit HTML window.
However, once you save, SharePoint lets you know that the code that it does not approve of has been stripped.
In this case, some of the embedded code has been stripped out.
Sometimes SharePoint will strip out all of it and sometimes it will only strip out parts which can cause an odd result. When it doubt, check back into the HTML source to see what has happened with your code and if it is still 100% intact.
Conclusion: while this used to work under some older SharePoint versions, it is generally not a reliable solution for SharePoint 2013.
Option #3: Using the Embed command
SharePoint 2013 includes an Embed command in the ribbon which can be great for adding code snippets to your page:
After clicking the command, you are prompted to insert your code and given a preview:
SharePoint creates a Script Editor webpart on the page for you. It even includes an “Edit Snippet” button, so you can go back and edit the code later.
Conclusion: in my experience, this works but is dependent on the complexity of the code. Test well before using.
Option 4: save as a text file, call via CEWP
Here is the file in Notepad++:
In this demo, I uploaded the HTML file to the document library on the same site as the page we are working with.
Tip: I tend to use the following rules of thumb as to where to upload these kinds of files:
- Think about if you want to save it in the standard Document library, or if you want to create a dedicated document library called “Scripts” or similar
- If the file will be called from just one single site, save it on the site
- if the file will be used across just one site collection, consider saving it at the root of the site collection or in the Style Library of that site collection (i.e. Styles/Scripts)
- If using across multiple site collections, choose the most logical place for it, i.e. on a root site collection
Next, place a Content Editor Web Part (CEWP) on the page and edit the webpart settings. At the top, add the link to the file and click “Apply” to save the changes.
The content should immediately display in the CEWP on the page.
Tip: if you wish to use the same webpart in many places, you could export the configured CEWP and import it as a custom webpart. You can then place it on a page and it will already be configured for you.
Conclusion: this is my favorite method due to the central storage of the files, ease of editing the files and reusability.
I was working on a document management system, where each client had its own site collection and projects were subsites under that site collection. I needed a way to show a list of available site collections from a main landing page. This needed to show all site collections, no security stripping and search rollup was not an option at this time. The easiest way then is to create a list that acts as a directory – just add the sites to the list manually.
The problem was the link to the sites. How best to do this?
Option 1: Hyperlink site column
Adding a hyperlink site column is easy. You get a clickable result in your field display.
The tricky part is dealing with the fact that a hyperlink column consists of two fields: the web address and then the description.
If you do not fill in a description, the URL is displayed when you view the item.
This approach has a few issues:
- Showing a text like “Link” is not very nice looking.
- When an end-user fills in the item, they may not be consistent with the result. You could add a description to the field, but this is still not foolproof.
- Even though the link is blue, not everyone will realize that you need to click the text to open the site – many people will still try to click the title and then just open the item. This leads to frustration.
Option 2: Creative use of calculated column
You can use a calculated column to display the link as an image, i.e. an arrow or something that is very obviously a link – how about something like this?
By choosing to use a calculated column, we have ensured that anywhere the column is used, the arrow will be displayed. This means that it will work in any view, any webpart, etc.
*** Update 2017-07-21: This worked on SharePoint 2013 and SharePoint Online until sometime this spring. When using SharePoint Online, it now only works in classic mode – it has been disabled in the new mode.
To replicate, follow these steps. The column names are not important, they are just suggestions.
- Upload an image to SharePoint, i.e. in your site assets library
- Create a new (site) column of the type “single line of text”, and call it “Site URL“
- Create a new (site) column of the type “calculated column” and call it “Site Link” or similar
- Use the formula as stated below, adjusted for your site and column names –
- Change the output of the column from “single line of text” to “number”
- Save the column and enjoy
The formula I used is as follows:
=IF(ISBLANK([Site URL]), "URL Missing", ("<a href="&[Site URL]&" target='_blank' alt='Open site in new window'><img src='/SiteAssets/link.png' style='height:20px; width:20px;' /></a>"))
Broken down, it has a few interesting elements:
- IF(ISBLANK([column name]), “URL Missing” – if the column with the URL is empty, it will show this text. If you leave off this structure, then the calculated column will simply be empty. You can also change the “URL Missing” text to whatever you would like, i.e. “Please fill in a URL”.
- A hyperlink is created based on the value of the Site URL column
- The link opens in a new window (this is specific to my example, as I expect a new window to be more useful for these users)
- Link to the image
- Set the image height – I found 15-20 pixels fit nicely into the column. You could also include a class from your CSS.
Tip when editing formulae in calculated columns: use Notepad++, as it will help you see when brackets are closed. Just make your changes in Notepad++, then copy them into the edit column window each time – this will make it far easier to work with.
Display as HTML
One of the coolest things about this solution is that generally, calculated columns cannot be rendered as HTML. Technically speaking, the contents of the column should just be displayed as plain text. Yet, here we are, with an nice arrow image being displayed and the link working beautifully. The trick is changing the returned datatype from single line of text to number. Once you do that, then the contents are rendered as HTML.
Credit for this solution goes to Danny Engelman at ICC – HTML in a Calculated Column / Field of a SharePoint View.
Site columns and content type hubs
In the real world solution, both the Site URL and Site Link columns were site columns, attached to a content type called Client Directory. The columns were also reused for a similar construction in a Project Directory custom list, which showed the subsites under each client site collection. Using a content type hub, these columns were replicated to each site collection and we were able to build a similar Project Directory in exactly the same way: simply fill in the URL, display Site Link column. This made the solution incredibly flexible and reusable.
I’m currently working on a project where we needed to assign a priority to issues based on impact and urgency. You could always let users figure this out for themselves, but it’s much better to automate it when there are clear definitions for each value and a table which translates the impact and urgency to priority.