7/17/2009

SharePoint: Convert a Links list to a Dropdown list

 

This article has been updated to include support for both SharePoint 2007 and 2010 and for better multiple browser support.  Click HERE for the updated version.

 

Problem: There is never enough room on your SharePoint home page. So what do you do if you have a long list of vendor links you would like to display on the home page. You would usually use a Links list and add a Links list web part. But it takes up too much space. How about a simple dropdown list?

     image

Solution: Yet another Content Editor Web Part (CEWP) trick!  A CEWP and some JavaScript…

   image

                                  image 

Steps:

  • Create your links list and add your links
  • Add the link list’s web part to the page
  • Add a Content Editor Web Part (CEWP) to the page just under the links list web part
  • Modify the CEWP and set a title then click Source Editor
  • Copy and paste the HTML and JavaScript below
  • Edit the JavaScript to change the word “Links” to the name of your links list web part (title of the web part, not the title of the actual list, although they may be the same)
      if (x(i).summary=="Links")     to
      if (x(i).summary=="Your Links List Title")
  • Exit the edit mode and see if it works

The HTML and JavaScript for the CEWP:

<select name="JumpToList" onchange="javascript:JumpToUrl(this(this.selectedIndex).value)"> <option>Jump to ...</option> </select> <script> // CEWP trick from techtrainingnotes.blogspot.com!

function JumpToUrl(url) { document.location.href = url } //code to hide the links list and populate the select list //Find the link list and hide it var x = document.getElementsByTagName("TABLE") // find all of the Tables var LinkList var i=0; for (i=0;i<x.length;i++) { if (x(i).summary=="Links") { // LinkList = x(i) //hide the links list web part (tables in tables in tables ...) x(i).parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none" } } //Copy all of the links from the link list to the select list var ToList = document.all("JumpToList") var links = LinkList.getElementsByTagName("A") // find all of the for (i=0;i<links.length;i++) { ToList.options[ToList.length] = new Option(links(i).innerHTML, links(i).href); } </script>

 

 

.

SharePoint: Custom Search Boxes – Google Search

 

A Google Search:

If you would like to make available a Google search of your public / anonymous access site you can replace the SharePoint search box with a custom control you create.

How it works:

First you need a URL to Google that passes your list of keywords and the “site:” option with the name of your site:

   http://www.google.com/search?hl=en&q=yourkeywords site:http://yourSiteURL
   (I guess “q” is short for “query”???)

To be “proper” the URL should be encoded:

   http://www.google.com/search?hl=en&q=yourkeywords+site%3Ahttp%3A%2F%2F

Then all you need is a Web User Control that you can create in Visual Studio or Notepad. This control can either redirect to Google using JavaScript or a little C# code.

 

Steps:

Note: This example requires deployment of files to the web server.

1) Create the Web User Control: (Name it GoogleSearch.ascx)
Replace “site:techtrainingnotes.blogspot.com” with your site URL.

<%@ Control Language="VB" ClassName="GoogleSearchReplacement" %>

<script runat="server">
  Protected Sub btnGoSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGoSearch.Click
    Response.Redirect("http://www.google.com/search?hl=en&q=" & search.Text + " site:techtrainingnotes.blogspot.com")
  End Sub
</script>

<asp:TextBox ID="search" runat="server"></asp:TextBox><asp:Button ID="btnGoSearch" runat="server" Text="Search Google" />

 

or if you prefer a JavaScript version:

<%@ Control %>
<input name="q" type="text"/><a href="" onclick="javascript:GoogleSearch();return false"><img src="/_layouts/images/gosearch.gif"/></a>
<script>
  function GoogleSearch()
  {
    document.location.href="http://www.google.com/search?q=" + document.all("q").value + " site:techtrainingnotes.blogspot.com"
  }
</script>

 

2) Create a feature to for the new control:

Create a Feature.xml file (you can use your own GUID for the ID if you like)
Note: this example has the scope set to Web (activated at the individual site level)

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
         Id="1AAC958B-FF05-4d96-B678-A14F581D187A"
         Description="Replace SharePoint search with Google search"
          Scope="Web"
          Title="Google Search"
          Version="1.0.0.0"          
         >
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>    
  </ElementManifests>  
</Feature>

 

Create the elements.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="SmallSearchInputBox" 
           ControlSrc="~/_ControlTemplates/GoogleSearch.ascx" Sequence="10">
  </Control>
</Elements>

Notes:

- this feature replaces the existing search ASCX file normally displayed in the Delegate Control named SmallSearchInputBox

 

Deploy the files to the 12 hive (to all of the web servers in the farm):

  • Copy GoogleSearch.ascx to ..\12\TEMPLATE\ControlTemplates folder in ..\12\
  • Create a new folder in ..\12\TEMPLATE\Features named GoogleSearch
  • Copy feature.xml and elements.xml to this folder
  • Run this STSADM from the command prompt to install the feature.

    STSADM –o installfeature –name GoogleSearch
  • Go to a site, select Site Actions, Site Settings and click Site features. Find this feature and activate it.
  • Test the search!

 

 

.

7/14/2009

SharePoint: Prevent the rescheduling of a task by dragging of the Gantt chart bar

 

When a task list is displayed using a Gantt view the user can reschedule a task (often by accident) by dragging the Gantt task bar with the mouse. It’s easy to prevent this with a tiny piece of JavaScript.

 

Steps:

  • Go the the page with the Gantt view
       http://yourserver/sites/yoursite/lists/yourtasklist/gantt.aspx
  • Click Site Actions, Site Settings, Edit Page
  • Click Add a Web Part and add a Content Editor Web Part (CEWP)
  • Move the CEWP below the Gantt chart web part
  • In the CEWP click Edit then Modify Shared Web Part
  • Click the Source Editor button
  • Paste the code from below
  • Exit the edit mode and try to drag one of the Gantt chart bars.

 

<script> document.all("GanttTable").ondragstart = function () {alert("Task dragging disabled!")} </script>

(The text between the script tags is all one line)

 

The result:

image

7/11/2009

SharePoint: Hiding Create options from MySite users

 

SharePoint does not give you and easy way to customize the Site Actions, Create page for selected users or sites. For example, you may not want MySite users to create Wikis or Discussion Boards, but everything else is ok.

The following “hack” is:
  - quick
  - easy
  - requires access to the web servers
  - not a form of security
  - and is not best practice!

        but is a cool hack.

 

Steps:

  • Go to your web server and to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
  • Open create.aspx in your favoriate text / page editor. (I used Notepad)   BACKUP THIS FILE BEFORE EDITING!
  • Scroll to the end and past the following JavaScript just before the "</asp:Content>" tag.

<script type="text/javascript" language="javascript">
if (document.location.href.match('/personal/')!=null)    //do this just for the mysites
{  

  var x = document.getElementsByTagName("TABLE") // find all of the TABLEs on the page  
  var i=0;
  for (i=0;i<x.length;i++)
  {

    if (x[i].className=="ms-itemstatic") //find the TDs styled for lists
    {

      if (x[i].innerHTML.match('Wiki|Survey|Sites and Workspaces')!=null)  // find the items to hide.
      {
        x[i].style.display='none'
      }
    }
  }
}
</script>

 

How it works:

  • it does its work only for mysites (and only if you have not changed the mysite URL from /personal/)
  • it finds all tables (each choice on the page is in a little table)
  • it finds any table that has the keywords you are looking for in the innerHTML.match line
    Note: this example hides any item with the words/phrases: "Wiki", "Survey" and "Sites and Workspaces"
    pick your phrases carefully and TEST!
  • it hides those that match.

Why not best practice?

  • you are modifying a Microsoft page that may be overwritten in the next service pack
  • if you don't document it in your disaster / rebuild plan, it will be forgotten.

Why not a form of security?

  • the user could go to another site and create the same item and note the URL used. Modify the URL and it works in any site.

.

7/10/2009

SharePoint: File name, folder name and path limits

 

The official numbers are:

  • folder name - not more than 128 characters  (123? see below)
  • file name - not more than 128 characters (128? see below)
  • total path to file - not more than 260 characters

And be aware that space and other special characters typically require three characters each.  Ie.  Test File  is  Test%20File

 

Built-in limits:

The page used to create folders and has a text box with a limit of 123 characters (go figure!).

The page used to edit properties for files has a text box with a limit of 123 characters, but that makes sense as Office 2007 has four character file extensions, so 123 + a period + 4 = 128.

And for completeness, here's the error message if you try to upload a file with too long of a name or a combined URL that is too long:

"The specified file or folder name is too long. The URL path for all files and folders must be 260 characters or less (and no more than 128 characters for any single file or folder name in the URL). Please type a shorter file or folder name."

 

.

SharePoint: Change SharePoint Fonts and Sizes

 

A simple question: “How can I change the fonts in SharePoint”

 

If only the answer were simple…

 

By the way, there is almost a simple answer here: http://hermansberghem.blogspot.com/2007/08/quickly-replace-default-sharepoint-font.html

Simply take his sample CSS and enclose them in <style> tags and insert in your master page just after SharePoint style sheet controls.

Why almost? It does not change everything. For example it does not change the fonts used in Quick Launch and Tabs. It’s a great idea, but needs some more work.

 

So let’s start with where SharePoint sets the fonts for a page:

  • CORE.CSS style sheet – There is one CORE.CSS for each language installed. For English the location is C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\STYLES
  • User selected theme (Site Actions, Site Settings, Theme) – The CSS file is located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\THEMES\themename\theme.css
  • User uploaded CSS file (MOSS publishing sites and sub-sites only: Site Actions, Site Settings, Master Page, Alternate CSS URL)
  • Inline CSS in the Master Page and Content pages
  • Custom CSS loaded from a Content page using the content place holder “PlaceHolderAdditionalPageHead”
  • Calendar CSS style sheets calendar.css and datepicker.css.
  • Like CORE.CSS, there is one of these for each language installed. For English the location is C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\STYLES

 

Solutions?

  • Edit CORE.CSS, CALENDAR.CSS and DATEPICKER.CSS on the servers. (bad idea – see below)
  • Create a new Theme and deploy to the server (good idea if you have access to the server’s drive C:)
  • Create your own style sheets and deploy them to your own libraries (that’s what we will describe here)

So, lots of places to look at and possibly edit. Where do you start? With CORE.CSS.

Where are these loaded by SharePoint? If you look in default.master you will see the two linked CSS files are loaded in the <HEAD> section of the Master Page:
    <SharePoint:CssLink runat="server"/>
   <SharePoint:Theme runat="server"/>

These custom SharePoint elements get expanded at runtime to a path with the detected language’s ID:

   <link rel="stylesheet" type="text/css"
      href="/_layouts/1033/styles/core.css?rev=…"/>
   <link rel="stylesheet" type="text/css" id="onetidThemeCSS"
      href="/_themes/Citrus/Citr1011-65001.css?rev=…"/

(Note the order they are loaded (or cascaded))

If you are looking at the source of a calendar page you will see two more CSS files:

   <link rel="stylesheet" type="text/css"
      href="/_layouts/1033/styles/calendar.css?rev=…"/>
   <link rel="stylesheet" type="text/css"
      href="/_layouts/1033/styles/datepicker.css?rev=…"/>
   <link rel="stylesheet" type="text/css"
      href="/_layouts/1033/styles/core.css?rev=…"/>
   <link rel="stylesheet" type="text/css" id="onetidThemeCSS"
      href="/_themes/Citrus/Citr1011-65001.css?rev=…"/

 

It is not recommended to modify CORE.CSS as it will most likely get updated with service packs and patches. You will need to create your own CSS file as load it (cascade it) after the list above. One way to do this is to make a copy of CORE.CSS.  (See the example steps below)

 

Where to Store your Custom CSS File

  • If you have access to the SharePoint web servers then you can store your final design here: C:\program files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\STYLES
  • If you are using MOSS publishing sites you can upload the CSS file from Site Actions, Site Settings, Master Page, Alternate CSS URL
  • A library in your site – This is great for testing and for final deployment when you don’t have access to the SharePoint web servers. Note: you will want to customize the access rights to this library to make it View Only for all except for the Site Administrators.

 

Now to change some fonts:

SharePoint defaults use a mixture of Tahoma and Verdana fonts. In this quick example we will change them all to “Comic Sans MS”.
CORE.css

First we need a copy of CORE.css. Why? All of the style names used in the out of the box SharePoint pages are defined there, over 800 of them. Most are named “ms-xxxxx”, but others have names such as “srch-xxxxx” and “Userxxxxx”. Some of these definitions will be superseded by styles with the same names in the selected site theme.

There is no single style used to set the font. You will need to use search and replace to update a large number of styles.

Note: To reduce the size of these frequently download files you could remove all of the CSS sections for your custom CSS file that do not have font references.

To get a copy of CORE.css:

If you have access to your server you could look here:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\STYLES

(Note: 1033 is for the English version)

Or you can grab a copy via the browser:

  1. Open a browser and go to:
    http://yourserver/yoursite/_layouts/1033/styles/core.css
  2. Click Open to open in SharePoint Designer (or click Save if you would like to have a local copy)
  3. Once in SharePoint Designer click File, Save As and save the file to your testing library in your site. (mycore.css)
  4. Now do a Search and Replace and replace tahoma with "Comic Sans MS". (include the quotes as there are spaces in the font name!)  I get 66 replacements!
  5. Repeat the search and replace and replace verdana with  "Comic Sans MS". (include the quotes!)   I get 90 replacements!
  6. In your default.master (or any test page, or inside of a testing Content Editor web part) add a link to your style sheet. If updating a master page, add the link anywhere after any existing CSS or Theme links.

    This example assumes you have uploaded the CSS file to a library in your site.

             <SharePoint:CssLink runat="server"/>
              <SharePoint:Theme runat="server"/>

              <link rel="stylesheet" type="text/css"
                        href="/sites/test/Shared%20Documents/mycore.css" />

 

Now display a page from your site and see if the fonts have all changed.

Now go to the calendar page. You will see that most fonts are updated, including some in the calendar. You have more work with the calendar style sheets to complete your edits. Repeat the steps above for calendar.css and datepicker.css. Get copies of the files, save them to your library (or the web servers), search and replace to change the fonts. Then add two more links:

              <SharePoint:CssLink runat="server"/>
              <SharePoint:Theme runat="server"/>

              <link rel="stylesheet" type="text/css"
                        href="/sites/test/Shared%20Documents/mycore.css" />

              <link rel="stylesheet" type="text/css"
                        href="/sites/test/Shared%20Documents/mycalendar.css" /> 
              <link rel="stylesheet" type="text/css"
                        href="/sites/test/Shared%20Documents/mydatepicker.css" />

Note: You could merge all three of your custom style sheets into a single file and only link to it.

 

Changing Font Size

The same steps used above can be used to change font sizes, but there are 26 different font sizes defined in CORE.CSS alone.

font-size:.68em; 4
font-size:.6em; 1
font-size:.7em; 6
font-size:.85em; 1
font-size:0.7em; 3
font-size:0px; 2
FONT-SIZE:1.0em; 7
font-size:1.2em; 2
font-size:100%; 2
font-size:10pt; 4
font-size:10px; 1
font-size:11pt; 1
font-size:120%; 1
font-size:12pt; 2
font-size:150%; 1
font-size:16pt; 3
font-size:1em; 4
font-size:1pt; 3
font-size:1px; 1
font-size:200%; 1
font-size:2px; 6
font-size:65%; 1
font-size:7pt; 2
font-size:80% 1
font-size:8pt; 115
font-size:9pt; 4
Grand Total 179

 

Font change thoughts and recommendations:

  • Most of the font sizes in core.css are absolute (pixels or points) and this prevents users from using the browser Text Size features to make a page easier to read. (do a web search on “SharePoint accessibility”)
  • You will have to do a lot of testing! Especially to find where there are hard coded font sizes in some pages and web parts.

 

For a great design resource and detailed information on customizing SharePoint using CSS see: http://www.heathersolomon.com/content/sp07cssreference.htm

 

.

7/09/2009

SharePoint: Missing “Save site as template” in sub sites

 

 Problem:

  • You create a sub site
  • You set Unique permissions (no inheritance)
  • You add a user who does not also have access to the top level site to the Owners group (or give them the Full Control permission).
  • The new “owner” goes to Site Actions, Site Settings and can’t find “Save site as template”.

For a similar problem relating to missing web parts see: SharePoint: Missing web parts on sub sites

 

Turns out it’s a rights issue. The templates are stored in the top level site’s Site Templates Gallery and your user does not have access to the top level site and its lists.

 

A quick fix is to grant contribute, or better, rights to the user to the parent site. But… you may not want them to have access to the top level site.

It's not necessary to inherit permissions from the parent or grant elevated rights to the parent. Just grant rights to the Site Template Gallery!

If you grant CONTRIBUTE rights to the Site Template Gallery of the top level site to the sub site owners then “Save site as template” will be available in the sub sties.

 

Here's how to duplicate my test:

  • Create a group a the top level site (SubSiteOwners)

    • give it no permissions to the top level site

    • add the sub site owners

  • From the top level site go to Site Actions, Site Settings, Galleries and click Site templates

    • Click Settings, Gallery Settings

    • Click Permissions for this gallery

    • Click Edit Permissions and OK

    • If your SubSiteOwners group is not displayed, click new and add it with CONTRIBUTE permissions, or if SubSiteOwners is displayed click and add the CONTRIBUTE permission

  • Create a sub site with Unique permissions (and do not use the parent’s visitor group)

  • Now to test: Open a new browser and login as a sub site owner user and

    • Go to Site Actions, Site Settings and click Save Site as Template

 

Mike

 

.

SharePoint: Missing web parts on sub sites

 

Problem:

  • You create a sub site
  • You set Unique permissions (no inheritance)
  • You add a user who does not also have access to the top level site to the Owners group (or give them the Full Control permission).
  • The new “owner” goes to add a web part and only sees the list and library web parts. All of the other normal web parts are not visible.

 

Turns out it’s a rights issue. The non-list web part definitions are stored in the top level site’s Web Parts Gallery and your user does not have access to the top level site and its lists.

 

A quick fix is to grant read, or better, rights to the user to the parent site. But… you may not want them to have access to the top level site.

It's not necessary to inherit permissions from the parent or grant elevated rights to the parent. Just grant rights to the Web Part Gallery!

If you grant READ rights to the Web Parts Gallery of the top level site to the sub site owners then all of the web parts in the gallery can be seen in the Add Web Part popup of the sub site.

As I bonus :-)  I found that if you grant CONTRIBUTE rights to the Site Template Gallery in the parent, then the sub site owners can now see and use "Save Site as Template"! While they cannot see the Site Templates gallery, they can see the saved templates in the Custom tab of the Create screen. (And a negative, they can see all of the saved templates created by all of the sub site owners.)

 

Here's how to duplicate my test:

  • Create a group a the top level site (SubSiteOwners)

    • give it no permissions to the top level site

    • add the sub site owners

  • From the top level site go to Site Actions, Site Settings, Galleries and click Web Parts

    • Click Settings, Gallery Settings

    • Click Permissions for this gallery

    • Click Edit Permissions and OK

    • If the SubSiteOwners group is not displayed, click new and add them with READ permissions, or if SubSiteOwners is displayed click and add the READ permission

  • From the top level site go to Site Actions, Site Settings, Galleries and click Site templates

    • Repeat steps for the Web Parts gallery but add the CONTRIBUTE permission

  • Create a sub site with Unique permissions (and do not use the parents visitor group)

  • Now to test: Open a new browser and login as a sub site owner user and

    • Edit the page and add a web part

    • Go to Site Actions, Site Settings and click Save Site as Template

If you want to be just a little trickier, instead of granting READ to the web part gallery itself, grant rights for each individual web part item. That way you can control which web parts users can see.

Mike

 

.

7/06/2009

SharePoint: The template you have chosen is invalid or cannot be found

 

I recently ran into “The template you have chosen is invalid or cannot be found” while creating a site from a template moved from another SharePoint server. The most likely cause is a missing feature on the destination server.

A recent source of this problem has been two recent updates, "Infrastructure Updates to MOSS 2007" and MOSS Service Pack 2 and a feature named S2SiteAdmin.

To find the missing feature use this great tool from CodePlex.com: “STP Inspector”   http://stpinspector.codeplex.com/

This tool will list all of the features needed by the STP file and flag those missing on the SharePoint server.

Note: this tool must be run on the server where you want to use the site template (STP) file.

 

.

7/02/2009

SharePoint: Time Zones

Your SharePoint server is not always in your time zone and your users are not always in your time zone. SharePoint can help!

 

To set the time zone for the entire site:
- Go to Site Actions, Site Settings and click Regional Settings in the Site Administration column, uncheck mark “Default” and set your regional options.

To set the time zone for a single user (and then SharePoint will adjust the all of the times on the SharePoint site to that user's timezone)
- Ask the user to click the Welcome menu then click My Settings and then My Regional Settings

 

 

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.