RSS Dave on Twitter

Displaying document titles as links.

Posted: December 29th, 2009 | Author: davecavins | Filed under: General SharePoint | Tags: , , , | 2 Comments »

On a recent project I had to migrate a large number of documents from a legacy system into SharePoint. In the old system users to choose what text would be displayed as the link. In most cases users chose not to use the actual file name as the link text.

The Problem

In SharePoint users don’t have as much control of what gets displayed. There is a ‘Title’ field but it can’t be used in a calculated column and on the standard document library it is not a required field.

Technically the file name could be used but this could lead to very long file names with spaces and special characters that could cause problems by forcing the page to scroll as well as creating some REALLY long URLs.

Depending on the type of document the actual file name may be irrelevant to the use while the title would be more helpful. For instance a in document library of meeting minutes the file names could just be the date of the meeting for example (12_03_2009.docx). The document title could be used to contain not only the date but other relevant information about the meeting like who attended or important issues that were discussed. Additionally the title field can support special characters and spaces that could be a problem in file names.

Read the rest of this entry »

Bookmark and Share
Share on Google Buzz

CSS-Tricks AnythingSlider in SharePoint

Posted: December 7th, 2009 | Author: davecavins | Filed under: SharePoint Design, Web Design | Tags: , , , , | 27 Comments »

Chris Coyier from CSS-Tricks built this really cool jQuery plugin that creates a content slider that will support any regular HTML in the slides. This is cool because many sliders I have used had limitations on what could be on the slides and did not offer many of the featuers the AnythingSlider does.

AnythingSlider in SharePoint

AnythingSlider in SharePoint

Setup

To get this working in SharePoint you will need to make sure you have a reference to jQuery in the page somewhere as well as a list for the slider to read from. For my example I am using an out of the box annoucements list.  You will also need the files for the plugin download the anythingSlider plugin from css-tricks.com.

  • In SharePoint Designer add a dataview webpart to the page with any field from your annoucements list.
  • Switch to code view and find the first <xsl> tag. It should be right after the closing <DatasSources> tag. 
  • Right click on the tag and choose “Select Tag”. Press delete, don’t worry we will be adding in our own xsl.
  • Select the auto generated xsl

  • Paste the following xsl into the page where you deleted the code.
  • <Xsl>
    <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
    	<xsl:output method="html" indent="no"/>
    	<xsl:decimal-format NaN=""/>
    	<xsl:param name="dvt_apos">&apos;</xsl:param>
    	<xsl:variable name="dvt_1_automode">0</xsl:variable>
    	<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
    		<xsl:call-template name="dvt_1"/>
    	</xsl:template>
    	<xsl:template name="dvt_1">
    		<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
    		    <link rel="stylesheet" href="css/page.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="css/slider.css" type="text/css" media="screen" />
    <script type="text/javascript" src="js/jquery.easing.1.2.js"></script> <script src="js/jquery.anythingslider.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript">
            function formatText(index, panel) {
    		  return index + &quot;&quot;;
    	    }
            $(function () {
                $(&apos;.anythingSlider&apos;).anythingSlider({
                    easing: &quot;easeInOutExpo&quot;,
                    autoPlay: true,
                    delay: 3000,
                    startStopped: false,
                    animationTime: 600,
                    hashTags: true,
                    buildNavigation: true,
             	pauseOnHover: true,
         	startText: &quot;Go&quot;,
         	stopText: &quot;Stop&quot;,
    	navigationFormatter: formatText
                });
                $(&quot;#slide-jump&quot;).click(function(){
                    $(&apos;.anythingSlider&apos;).anythingSlider(6);
                });
            });
        </script>
    <div class="anythingSlider">
    	<div class="wrapper">
    		<ul>
    		<xsl:call-template name="dvt_1.body">
    			<xsl:with-param name="Rows" select="$Rows" />
    			</xsl:call-template>
    		</ul>
    		    </div>
            </div>
    	</xsl:template>
    	<xsl:template name="dvt_1.body">
    		<xsl:param name="Rows" />
    		<xsl:for-each select="$Rows">
    			<xsl:call-template name="dvt_1.rowview" />
    		</xsl:for-each>
    	</xsl:template>
    	<xsl:template name="dvt_1.rowview">
    		<li>
    		<div class="textSlide">
    <!-- display the item title and a link to the item -->
    <h3><a href="/{@FileDirRef}/DispForm.aspx?ID={@ID}" title="{@Title}"><xsl:value-of select="@Title" /></a></h3>
    <!-- display the body of the item  -->
    	<xsl:value-of select="@Body" disable-output-escaping="yes" />
    	</div>
    	</li></xsl:template>
    </xsl:stylesheet>
    </Xsl>
    
  • Important: Adjust the links on the code so that point to your local copies of the css easing and plugin files.

Notes

 I made a few small changes in the css file to make things work better with SharePoint.  In page.css file I deleted several of the classes so they would not interfere with SharePoint’s styles.  In the xsl I used a div with a class of  .textslide to wrap the content so I had to change that in page.css as well.  To keep long annoucements from breaking the design I set the overflow on the .textslide div to hidden. Below is the code I used in page.css.  

/*hide content that is too long */
.textSlide { padding: 10px 30px; overflow:hidden; }
.textSlide h3  { font: 20px Georgia, Serif; margin-bottom:12px; }
.textSlide h4  { text-transform: uppercase; font: 15px Georgia, Serif; margin: 10px 0; }
.textSlide ul  { list-style: disc; margin: 0 0 0 25px; }
.textSlide ul li  { display: list-item; }

 I did not make any changes to slider.css. It may be easier to just combine the tow files to keep things simple and reduce page load times.

Conclusion

The AnythingSlider plugin is lightweight, powerful and easy to customize.  Adding this type of functionality that is common on regular websites to a SharePoint site can help guide users to important information and of course make your site ‘cooler’ than the average SharePoint site. 

The code above just shows all the items in the list but once you have it working it is easy to add your own sort/filter parameters to the data view so only certain items are shown.

The slider could also be implemented to run off of the SharePoint list web service the same way I did in this post.  If you have any questions or comments feel free to post.

Bookmark and Share
Share on Google Buzz

Updating the People Picker

Posted: December 4th, 2009 | Author: davecavins | Filed under: General SharePoint | Tags: , , | No Comments »

So I was working with a friend on a custom SharePoint list. When users create a new item certain fields needed to automatically populate with information from their profile. We ran into issues when trying to populate the people picker.

Scripts like SPFF can be used to accomplish this but we needed something else because we wanted to read in the current user’s information from the SharePoint web service. Additionally we wanted to avoid passing information using the query string because users would be able to access the form through multiple links.

People Picker

People Picker

So to prefill the form with some information we used a simple jQuery script in a Content Editor Web Part on the NewItem.aspx page. Initially we tried to target the input by using its title. This did not work so I looked at the code of the page using FireBug. It turns out that the field is actually a hidden textarea and what you see on the screen is actually just a div with a class of ms-inputuserfield. Here is part of the code we used to populate the people picker.

<script type="text/javascript">
var user = "dcavins"
$(document).ready(function() {
$('div.ms-inputuserfield').text(user);
});
</script>

This script can used along with the SP web services to prepopulate the people picker and other fields of a list. This is useful if you have a contacts list where you want people to be able to add themselves or a task list where users are supposed to assign items to themselves. Prepopulating fields makes it easier for the user saving them time.

The Rich Text Field is similar to the people picker in that it also hides the actual textarea and uses a div instead. In a later post I will explain how to use the web service to prepopulate list fields with information from the current users profile.

Bookmark and Share
Share on Google Buzz
Get Adobe Flash playerPlugin by wpburn.com wordpress themes