Tuesday, December 22, 2009

jQuery in SharePoint Example - Rounded Corners

A recent project involved the branding of MOSS to incorporate custom design elements as supplied in a PhotoShop page mockup. One of these design requirements was rounding the external corners of the quick launch menu.

Hmmm, what to do. There are plenty of techniques discussed on the web for achieving this outcome, but often the basis for these techniques is to start with clean, web-standards compliant HTML. That's certainly not what SharePoint provides - I needed to work with the HTML that is created by the mixture of master pages and user controls, and did not want to override standard elements for this styling exercise. One aim was to minimize the changes, if any, to the master page.

Many of the rounded corner approaches use JavaScript. And I was, at the time of this project, starting to see the potential of jQuery combined with SharePoint. So a little more research located a neat way forward - the jQuery.Round plug-in.

After a few minutes (hours?) experimentation I derived the jQuery statements to apply rounded corners to the menu. This of course also required adding references to the jQuery and jQuery.round libraries in the master page - so it was necessary after all to change that page!

The statements were:

function AddQuickLaunchCorners()
{
    $(".ms-quicklaunchouter").corner("10px");
    $("div.ms-quickLaunch h3.ms-standardheader span div.ms-quicklaunchheader").css("background-color", "#c1ecff").corner("top 7px");
    $("table.ms-recyclebin:last td").corner("bottom 7px");
}

Note the assumption in the last JavaScript statement that the recycle bin will be the bottom row in the quick launch menu.

These statements, together with modifications to some of the other CSS styles, resulted in the following look for the quick launch menu:




But then I came across a very annoying behaviour. Imagine the following scenario:

  • I view a page containing this menu in one tab in IE7
  • Then I open another tab in IE7 and navigate around any page in that second tab

Not an unusual behaviour really. But on returning to the first tab displaying the SharePoint page with menu, this is what the menu then looked like:


Yeuch! More "minutes" of investigation lead to the inclusion of the following code in the JavaScript file applying the dynamic styling to the page:

window.onfocus = ReapplyQuickLaunchCorners;

function ReapplyQuickLaunchCorners()
{
    RemoveQuickLaunchCorners();
    AddQuickLaunchCorners();
}

function RemoveQuickLaunchCorners()
{
    $("div.ms-quicklaunchouter>div:not(.ms-quickLaunch)").remove();
    $("div.ms-quickLaunch h3.ms-standardheader span div.ms-quicklaunchheader>div").remove();
    $("table.ms-recyclebin:last td>div").remove();
}

Not a nice solution (OK, it's a hack!) but it works and I ran out of time.

So where am I leading with this post - well, just to illustrate the great things you can do with jQuery to mould SharePoint. Sometime I'll blog about using jQuery for AJAX calls to the MOSS profile search web services, but that's for another time.....


Sunday, December 20, 2009

Renaming a stand-alone SharePoint 2010 server

Have you gotten around to trying out the SharePoint 2010 public beta yet?

In an effort to provide everyone that would want one access to a virtual machine with SharePoint 2010 Beta, Visual Studio 2010 Beta and SharePoint Designer 2010 Beta, I decided to create such VM and put it up on a file share so that anyone can grab a copy and get going and thought I’d blog about how I did it.

I decided to use Windows 7 on the image, just to prove that it works. Now, SharePoint 2010 requires a 64-bit OS, which means that Virtual PC is out unfortunately. But VirtualBox and VMWare Player are both excellent and free. Personally, I created the image using Virtual Box, and then exported a copy in VMWare format so that our developers could choose whichever VM solution they preferred.

Unfortunately, it wasn’t as easy as just running the SharePoint 2010 installation as you would on server OS. As described in this article, you need to extract the setup files and modify a configuration file to allow the installer to run on Windows 7. Another caveat I came across was that the SharePoint Products and Technologies Configuration Wizard would fail on step 8, “creating sample data”, with an error message about “Unrecognized attribute ‘allowInsecureTransport’”. But installing the hotfixKB976462, I could finally run the wizard successfully.

The last thing I had to figure out was the easiest way of renaming the VM after cloning it to avoid name collisions on the network. I found this guide for SharePoint 2007, and it still works, but since SharePoint 2010 includes the PowerShell based Management Shell, I performed some of the steps using it instead.

Here are the steps I took:

  1. Start the management shell
  2. Run “Rename-SPServer -Identity -Name
  3. Change the name of the server (in the computer properties dialog)
  4. Reboot
  5. Start the management shell again
  6. Run “Set-SPAlternateURL -Identity -Url
  7. Run “Set-SPAlternateURL -Identity -Url
  8. And you’re good to go! :)

If you run in to access denied errors, try running the management shell as administrator.

Knowing just how lazy we developers are, I created a PowerShell script that performed the entire name change after prompting the user for the new server name and the central administration port and put the script on the desktop on the original VM image. That way, the developer just has to run the script after booting a newly cloned image. Clean and easy. :)

Here’s the source for the PowerShell script:

Echo "Loading SharePoint extensions..." $ver = $host | select version if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"} Add-PsSnapin Microsoft.SharePoint.PowerShell  $newSrvName = Read-Host -Prompt "Enter new server name" $caport = Read-Host -Prompt "Enter Central Administration port"  echo "Renaming server..." $ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem $oldSrvName = $ComputerInfo.Name $ComputerInfo.Rename($newSrvName)  echo "Updating alternate access mappings..."  Set-SPAlternateURL -Identity "http://$oldSrvName`:$caport" -Url "http://$newSrvName`:$caport" Set-SPAlternateURL -Identity "http://$oldSrvName" -Url "http://$newSrvName"  echo "Renaming server in SharePoint configuration..." Rename-SPServer -Identity "$oldSrvName" -Name "$newSrvName"  echo "Done! RESTART the server for the changes to take effect" $restart = Read-Host -Prompt "Restart now? [Y/N]" if ($restart -eq "Y") {  shutdown -r -t 10 -f -c "Restarting server after name change" }

Thursday, December 3, 2009

SharePoint Workflow Authoring in Visio Premium 2010

Visio has long been the tool of choice for documenting processes. Ever since the introduction of workflow support in Microsoft Office SharePoint Server 2007, we have been hearing from customers, “wouldn’t it be great to visualize SharePoint workflows in Visio like flowcharts? Wouldn’t it also be great to go from Visio business process diagrams to executable workflows on SharePoint?”

In Visio Premium 2010, we have partnered with the SharePoint Designer team to bring you that functionality to life. In this blog post and the next, we will introduce to you how you can author SharePoint workflows just like any flowcharts in Visio, and how such workflows can then be imported into SharePoint Designer 2010 for further editing before it can be executed in SharePoint.

What are SharePoint Workflows?

First of all, what are SharePoint Workflows? Workflow is just another way of saying process flow, something most Visio users are already familiar with. In SharePoint, there are pre-defined common activities (e.g. Send email) that can be executed together with others, and together this forms a “workflow”. Some SharePoint workflow examples include: document approval workflow, expense approval workflow, and document review feedback workflow. A user may originally create the business workflow in Visio, as shown below:



That same workflow, implemented as a SharePoint Workflow, can look like the following in SharePoint Designer 2010:


So how can you go from a business flowchart in Visio to a workflow published to SharePoint?

Starting from Visio: New SharePoint Workflow Template

In Visio Premium 2010, we are introducing a brand new drawing template just for SharePoint Workflow. When you start up Visio, you can go to New->Flowchart->Microsoft SharePoint Workflow in order to start authoring a Visio SharePoint Workflow from scratch.

This is especially handy for Business Analysts or
Process Analysts who are already familiar with flowcharting in Visio, but would like to automate the workflow to be executed in SharePoint.

Upon opening the drawing, you will notice that key SharePoint activities are available in three separate stencils: SharePoint Workflow Actions, SharePoint Workflow Conditions, and SharePoint Workflow Terminators. Every SharePoint activity directly maps to those available in SharePoint Designer 2010.



To start authoring a SharePoint workflow, simply drop shapes to the drawing canvas, just like creating any basic flowchart in Visio. Note you can modify the original shape text and replace it with text more relevant to your business process:



Exporting Workflow to SharePoint Designer 2010

When you are done with authoring your workflow, you can export it in a file that can be imported by SharePoint Designer 2010. By exporting the workflow to SharePoint Designer 2010, SharePoint specialists or IT professionals alike can further parameterize the workflows by binding workflow activity fields with SharePoint lookups and then publish as executable workflows.

To export, simply go to the Process tab, and click Export:

Visio will automatically validate the workflow first to make sure the workflow is valid (for more information about our validation feature, see this earlier blog post). In the event that your workflow has issues, an Issues window will pop up, and the shape with the issue will be highlighted.

After you fix all issues, the workflow will be exported as a Visio Workflow Interchange (*.vwi) file, which can be imported into SharePoint Designer 2010.

Upcoming Post: Part 2 of SharePoint Workflow Authoring in Visio Premium 2010

Tuesday, December 1, 2009

How to build the Silverlight web part?

Steps to create this on your own site using SharePoint Designer (no server access or web part installation required).

Note: Copy any code below into notepad first. Only PNG and JPG are supported by Silverlight 1.0.

Assuming you have a SharePoint picture library already created.

  1. Create a Document Library to hold your web part page and the required SilverLight files (set template to Web Part Page)
  2. Create a folder called script in the document library
  3. Copy the following files from http://www.codeplex.com/bjsspv/Release/ProjectReleases.aspx?ReleaseId=6444 into the script folder
    1. Createsilverlight.js
    2. Main.js
    3. Silverlight.js
    4. Scene.xaml
    5. Photoitem.xaml
  4. Create a Web Part Page in the library
  5. Edit the web part page in SharePoint Designer
  6. Insert a Data View of your picture Library (just select one field from the data source view)
  7. Set the data view layout to Plain Layout
  8. Add the following code immediately before the tag in the




    Loading...]]>

  9. Replace the dvt_1 template with the following


    PlnTitl

]]>

  • Replace all the code between the with

    localScene.PhotoItemsUrls[''] = new BinaryJamSFSPartPhotoUrls('http://www.wssdemo.com','http://www.wssdemo.com/today/_t/_.jpg');

    This adds the image url and calculates the thumbnail for the image (_ext.jpg). Substitute www.wssdemo.com with your site url and Today with your picture library. Important: If your picture library is in a sub site, the first URL should be to your root site collection, not the sub site.

  • Save your page and view it in the browser (mouse over the bottom of the image to get the selector to display)
  • Sunday, November 1, 2009

    Solve SharePoint Performance Problems in SQL Server

    Most poorly performing SharePoint sites are caused by underlying SQL server configuration, or lack there off, settings.
    One of the big impacts of using SharePoint Central Admin to create content databases is that they will be based on the Model DB template.
    This results in the following:
    Data File = 10Mb with auto grow = 1Mb
    Log File = 1Mg with auto grow = 10%
    This means that almost every time a user saves an office document, SQL will have to "auto grow" the database files and there is an overhead to this operation. The SQL Disk Usage report will give you an indication of this impact on existing content databases that started with the default size.


    This is a relatively small content database but has already been extended many hundreds of times with 45ms per second in this case.
    Extending the Database (data and log files) manually to a size that would provide for 6/12 months projected storage requirements results in a noticeable improvement in end user response times not only for saving documents but in overall responsiveness of all sites in the database.
    There is much more to designing a good SQL platform for SharePoint, this is just some evidence in case you didn't believe it...

    New SharePoint 2010 content for download

    SharePoint 2010: Developer Platform White Paper

    This white paper provides an overview of the SharePoint 2010 Developer Platform for ASP.NET developers.

    SharePoint 2010: SharePoint Developer Platform Wall Poster

    The SharePoint 2010 Developer Platform wall poster (PDF format) shows a view of the SharePoint 2010 developer tools, community ecosystem, execution environment, Sharepoint Server 2010 workloads, and target application types. The poster is intended to be printed at 24 inches x 36 inches (61 centimeters x 91 centimeters).

    SharePoint 2010: Getting Started with Development on SharePoint 2010: Hands on Labs in C# and Visual Basic

    Use these 10 hands-on lab manuals for SharePoint 2010 to get started learning SharePoint 2010 development.

    SharePoint 2010: Developer and IT Professional Learning This document provides information to help developers and IT professionals learn Microsoft SharePoint 2010.

    SharePoint 2010: Professional Developer Evaluation Guide and Walkthroughs

    The SharePoint 2010 developer evaluation guide describes the SharePoint 2010 developer platform, including walkthroughs of some of the new capabilities for developers.

    Enterprise Search Planning for SharePoint Server 2010

    This model describes primary architecture design decisions for search environments.

    Design Search for SharePoint Server This model describes the steps to determine a basic design for a SharePoint Server 2010 search architecture.

    SharePoint Server 2010 Search Architecture


    This model describes the physical and logical architecture components of the search system.

    Getting started with BI in SharePoint Server 2010

    Discusses the business intelligence tools available in SharePoint Server 2010

    SharePoint Server 2010 Evaluation Guide

    Introduction and overview of SharePoint Server 2010 for IT pros.

    SharePoint Enterprise Search

    Compares and contrasts search technologies in SharePoint 2010 Products

    Topologies for SharePoint Server 2010

    Describes common ways to build and scale farm topologies, including planning which servers to start services on.

    Hosting Environments for SharePoint 2010 Products

    Summarizes the support for hosting environments and illustrates common hosting architectures.

    Services in SharePoint Products 2010


    Describes and illustrates the services architecture, including and common ways to deploy services in your overall solution design.

    Cross-farm Services in SharePoint 2010 Products

    Illustrates how to deploy services across farms to provide centralized administration of services.

    Business Connectivity Services poster

    Microsoft Business Connectivity Services enable users to interact with external data by using SharePoint lists and Microsoft Office 2010.

    Upgrade planning poster

    Describes requirements and considerations for planning to upgrade to SharePoint Server 2010

    Upgrading services poster

    You need to give special consideration to the issues involved when you upgrade services from the previous version of SharePoint Server.

    Upgrade testing poster

    To help ensure a smooth transition to SharePoint Server 2010, perform a trial upgrade to find issues likely to surface during the actual process.

    Upgrade approaches poster This model describes the three basic approaches to upgrading to SharePoint Server 2010: in-place, database attach, or a hybrid of the two.

    Forefront Protection 2010 for SharePoint Beta 2 Microsoft Forefront Protection 2010 for SharePoint prevents users from uploading or downloading documents containing malware, out-policy content, or sensitive information to SharePoint libraries.

    Microsoft Forefront Server Security 2010 Privacy Statement This document describes the privacy policy for Microsoft Forefront Security 2010 for Exchange and Microsoft Forefront Security 2010 for SharePoint.

    Microsoft Online Services 2010 CTP Help Microsoft Online Services 2010 CTP Help is a small set of documents that provide basic "Get Started" information for the July 2009 Community Technology Preview of Microsoft Online Services 2010.

    SharePoint Products and Technologies: 2010 (Technical Preview) Developer Documentation This download provides an early technical preview of the SharePoint Products and Technologies: 2010 developer documentation.

    Monday, October 26, 2009

    Book Review: Professional SharePoint Designer 2007

    Finally, a book (and a great one in that) covering SharePoint Designer! I recently finished reading Professional Microsoft Office SharePoint Designer 2007, authored by MVPs Woodrow Windischman, Bryan Phillips, and Asif Rehmani. With Microsoft making SPD 2007 available as a free download, it’s important that users of the product understand how to use it properly.

    The authors did an incredible job covering the aspects of SPD from multiple perspectives. I enjoyed how they even included sections on developing solutions with Visual Studio. It was apparent those sections were added with the intent on getting readers familiar with the various options and methods they have available for developing extended functionality outside SPD, so don’t be disappointed if you don’t feel it’s advanced enough – remember that this isn’t a core development book.

    The one thing I loved the most about the book was the style of writing; the authors did a great job simplifying walking through the features of SPD without losing my attention. The level of detail and simplicity was balanced very well throughout the book. I learned a lot of things reading this book and I believe any user, no matter how good he/she is with SPD, can learn a new thing or two from reading this book as well.

    SharePoint Designer 2007 is a tremendous and powerful software. With Microsoft making it available to download for free, users need to have a strong understanding of how to work with it, and more importantly, how to avoid running into problems with it.

    Tip: How to delete the default Shared Services Provider (SSP)

    Here’s a quick tip for anyone new at administrating MOSS 2007.

    When attempting to delete the default SSP through Central Administration, the “Delete” option is grayed out. To work around this, run the below command using STSADM.

    stsadm –o deletessp –deletedatabases -force
    The “–deletedatabases” parameter is optional. The “–force” parameter is required when deleting the default SSP. It’s optional when deleting any other SSP, and is used to force the timer job to complete the deletion.

    Sunday, October 4, 2009

    Business Data Catalog in MOSS 2007

    Overview
    As per Microsoft, Business Data Catalog (BDC) is a “new business integration feature available in Microsoft Office Sharepoint Server 2007. It is a shared service and it enables MOSS 2007 to surface business data from back-end server applications without any coding.”
    Why BDC?
    All the data entered into the Sharepoint system gets stored in the content database of that particular Sharepoint application. So by default, a Sharepoint site will get information from its content database. But it is quite natural for an organization to have information stored in multiple databases by numerous applications throughout the organization. For example, inventory software stores its data in a database that is different from a CRM software storing data in a database. But people will find is extremely useful if provided with a space where they can have every bit of information from each and every department in the organization ranging from the up-to-minute logistics information to the up-to-date sales analysis. The BDC feature of Microsoft Office Sharepoint Server 2007 provides the needed business integration for integrating the line of business (LOB) applications with the Sharepoint.
    What is BDC?
    Business Data Catalog provides built in support for displaying data from two data sources.
    · Databases
    · Web Services
    Microsoft promises a “no coding” approach for integrating LOB applications with Sharepoint. Business Data Catalog provides access to the data sources through a metadata model that provides a consistent and simplified client object model. So it is the metadata authors who describe the API of the business applications in xml. After this, the administrators will associate this metadata with the Sharepoint application after which the LOB data is available in the Sharepoint system.

    Creating Lists using Sharepoint Object Model

    before starting with the article first go through http://dotnetdreamer.com/2009/05/24/creating-sites-using-sharepoint-object-model/

    Listed below are the Sharepoint site components and their corresponding object in the sharepoint object model.

    Sharepoint Site Architecture Component Object in Sharepoint Object Model
    Site Collection SPSite
    Site SPWeb
    List Collection SPListCollection
    List SPList
    List Field Collection SPFieldCollection
    List Field SPField
    List Item Collection SPListItemCollection
    List Item SPListItem
    Steps to create a new Sharepoint List:

    Open Visual Studio. Create a new Windows Forms project.
    Add a textboxes, one to accept the name of the site collection and another to accept the name of the new site to be created under the site collection.
    Add a button that creates the new site.
    Add reference to Microsoft.Sharepoint dll. This dll is represented by the name Windows Sharepoint Services in the Add Reference dialog box.
    Add the namespace of Microsoft.Sharepoint dll like this.
    using Microsoft.Sharepoint;
    In the button click event, open the site collection.
    SPSite siteCollection = new SPSite(txtSiteCollectionUrl.Text);
    Now open the top level site of the site collection.
    SPWeb site = siteCollection.OpenWeb();
    If you want to open a different site under the site collection other than the top level site, you can use the overloaded methods of the OpenWeb() method that accepts the name of the site as argument.
    The Lists property present in the SPWeb object will return all the lists that are present in that site as an SPListCollection object
    SPListCollection listCollection = site.Lists;
    In order to add a new list, use the add method of the SPListCollection object.
    listCollection.Add(”listname”, “list description”, SPListTemplateType.GenericList);
    Note that the third argument accepts the template in which the list should be created. GenericTemplate represents the custom list. We can choose the template we need from the SPListTemplateType enum.
    Close and dispose and the site and site collection
    site.dispose();
    siteCollection.close();
    The complete code can be found below..

    using System;

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.SharePoint;

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    SPSite siteCollection;
    SPWeb site;

    private void btnCreateSite_Click(object sender, EventArgs e)
    {

    try
    {
    siteCollection = new SPSite(txtSiteCollection.Text);
    site = siteCollection.OpenWeb();
    SPListCollection listCollection = site.Lists;

    listCollection.Add(txtListName.Text, “list description”, SPListTemplateType.GenericList);
    }
    catch (Exception)
    { }
    finally
    {
    site.Dispose();
    siteCollection.Close();
    }
    }

    }
    }

    Hope this is useful.

    Friday, September 18, 2009

    jQuery and jCarousel in SharePoint

    I recently had to integrate jCarousel into a SharePoint web part. Since jCarousel is a plugin for jQuery, it means I also had to get jQuery integrated with SharePoint. In order to accomplish this, I followed some good feature packaging instructions found from a few different blog posts:
    SharePoint jQuery Deployment Feature
    SharePoint + jQuery = Stay Here Feature
    SharePoint Slideshow Web Part
    After figuring out how to package jCarousel and jQuery using SharePoint delegate controls, I was ready for business with the implementation of the web part.
    The web part itself was nothing fancy. I used a Repeater control to generate the list item (LI) elements with the content I needed in the carousel. I wrapped the Repeater in an unordered list (UL) which was wrapped in a DIV tag that had the runat attribute set to server. So basically, I just followed the mark up instructions provided in the jCarousel documentation.
    The wrapping DIV tag was used in my webpart code to initialize jCarousel. The code snippet below shows how I implemented it:

    protected override void OnLoad(EventArgs e)
    {
    if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(), this.ClientID))
    {
    Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, @"

    ");
    }
    }

    Thursday, September 10, 2009

    18 ways to improve your Body Language!!!

    There is no specific advice on how to use your body language. What you do might be interpreted in several ways, depending on the setting and who you are talking to. You’ll probably want to use your body language differently when talking to your boss compared to when you talk to a girl/guy you’re interested in. These are some common interpretations of body language and often more effective ways to communicate with your body.

    First, to change your body language you must be aware of your body language. Notice how you sit, how you stand, how you use you hands and legs, what you do while talking to someone.

    You might want to practice in front of a mirror. Yeah, it might seem silly but no one is watching you. This will give you good feedback on how you look to other people and give you an opportunity to practise a bit before going out into the world.

    Another tip is to close your eyes and visualize how you would stand and sit to feel confident, open and relaxed or whatever you want to communicate. See yourself move like that version of yourself. Then try it out.

    You might also want observe friends, role models, movie stars or other people you think has good body language. Observe what they do and you don’t. Take bits and pieces you like from different people. Try using what you can learn from them.

    Some of these tips might seem like you are faking something. But fake it til you make it is a useful way to learn something new. And remember, feelings work backwards too. If you smile a bit more you will feel happier. If you sit up straight you will feel more energetic and in control. If you slow down your movements you’ll feel calmer. Your feelings will actually reinforce your new behaviours and feelings of weirdness will dissipate.

    In the beginning easy it’s to exaggerate your body language. You might sit with your legs almost ridiculously far apart or sit up straight in a tense pose all the time. That’s ok. And people aren’t looking as much as you think, they are worrying about their own problems. Just play around a bit, practice and monitor yourself to find a comfortable balance.

    1. Don’t cross your arms or legs – You have probably already heard you shouldn’t cross your arms as it might make you seem defensive or guarded. This goes for your legs too. Keep your arms and legs open.

    2. Have eye contact, but don’t stare – If there are several people you are talking to, give them all some eye contact to create a better connection and see if they are listening. Keeping too much eye-contact might creep people out. Giving no eye-contact might make you seem insecure. If you are not used to keeping eye-contact it might feel a little hard or scary in the beginning but keep working on it and you’ll get used to it.

    3. Don’t be afraid to take up some space – Taking up space by for example sitting or standing with your legs apart a bit signals self-confidence and that you are comfortable in your own skin.

    4. Relax your shoulders – When you feel tense it’s easily winds up as tension in your shoulders. They might move up and forward a bit. Try to relax. Try to loosen up by shaking the shoulders a bit and move them back slightly.

    5. Nod when they are talking – nod once in a while to signal that you are listening. But don’t overdo it and peck like Woody Woodpecker.

    6. Don’t slouch, sit up straight – but in a relaxed way, not in a too tense manner.

    7. Lean, but not too much – If you want to show that you are interested in what someone is saying, lean toward the person talking. If you want to show that you’re confident in yourself and relaxed lean back a bit. But don’t lean in too much or you might seem needy and desperate for some approval. Or lean back too much or you might seem arrogant and distant.

    8. Smile and laugh – lighten up, don’t take yourself too seriously. Relax a bit, smile and laugh when someone says something funny. People will be a lot more inclined to listen to you if you seem to be a positive person. But don’t be the first to laugh at your own jokes, it makes you seem nervous and needy. Smile when you are introduced to someone but don’t keep a smile plastered on your face, you’ll seem insincere.

    9. Don’t touch your face – it might make you seem nervous and can be distracting for the listeners or the people in the conversation.

    10. Keep you head up - Don’t keep your eyes on the ground, it might make you seem insecure and a bit lost. Keep your head up straight and your eyes towards the horizon.

    11. Slow down a bit – this goes for many things. Walking slower not only makes you seem more calm and confident, it will also make you feel less stressed. If someone addresses you, don’t snap you’re neck in their direction, turn it a bit more slowly instead.

    12. Don’t fidget – try to avoid, phase out or transform fidgety movement and nervous ticks such as shaking your leg or tapping your fingers against the table rapidly. You’ll seem nervous and fidgeting can be a distracting when you try to get something across. Declutter your movements if you are all over the place. Try to relax, slow down and focus your movements.

    13. Use your hands more confidently – instead of fidgeting with your hands and scratching your face use them to communicate what you are trying to say. Use your hands to describe something or to add weight to a point you are trying to make. But don’t use them to much or it might become distracting. And don’t let your hands flail around, use them with some control.


    14. Lower your drink – don’t hold your drink in front of your chest. In fact, don’t hold anything in front of your heart as it will make you seem guarded and distant. Lower it and hold it beside your leg instead.


    15. Realise where you spine ends – many people (including me until recently) might sit or stand with a straight back in a good posture. However, they might think that the spine ends where the neck begins and therefore crane the neck forward in a Montgomery Burns-pose. Your spine ends in the back of your head. Keep you whole spine straight and aligned for better posture.


    16. Don’t stand too close –one of the things we learned from Seinfeld is that everybody gets weirded out by a close-talker. Let people have their personal space, don’t invade it.


    17. Mirror - Often when you get along with a person, when the two of you get a good connection, you will start to mirror each other unconsciously. That means that you mirror the other person’s body language a bit. To make the connection better you can try a bit of proactive mirroring. If he leans forward, you might lean forward. If she holds her hands on her thighs, you might do the same. But don’t react instantly and don’t mirror every change in body language. Then weirdness will ensue.


    18. Keep a good attitude – last but not least, keep a positive, open and relaxed attitude. How you feel will come through in your body language and can make a major difference. For information on how make yourself feel better read 10 ways to change how you feel and for relaxation try A very simple way to feel relaxed for 24 hours.


    You can change your body language but as all new habits it takes a while. Especially things like keeping you head up might take time to correct if you have spent thousands of days looking at your feet. And if you try and change to many things at once it might become confusing and feel overwhelming.


    Take a couple of these body language bits to work on every day for three to four weeks. By then they should have developed into new habits and something you’ll do without even thinking about it. If not, keep on until it sticks. Then take another couple of things you’d like to change and work on them.

    Tuesday, September 8, 2009

    Creating tabbed windows in Sharepoint with jQuery

    To get this working you need a Page Layout. I use one for our Home Page, called SiteHomePage.aspx. Open the page in your favorite editor (or take Sharepoint Designer), grab a cup of coffee and get started!

    Set up the base structure with XHTML
    I first started by creating the base structure. This is basically nothing else than a list with the Tab-titles and some DIVS for the Tab-content. The Tab-content will be added later using Web Part Zones.


    Adding layout using CSS
    Next, you need some CSS to make it display like tabs. I used these styles:

    #tabs ul.tabNavigation{
    margin: 0;
    padding: 0;
    list-style: none;
    height: 22px;
    /* Push the tabs 1px down to hide the top-border of the tabbedWindow */
    position: relative;
    top: 1px;
    }
    #tabs ul.tabNavigation li{
    float: left;
    padding: 0;
    margin: 0 5px 0 0;
    background: none;
    }
    #tabs ul.tabNavigation a{
    background: url("tab_out.gif") no-repeat 0 0;
    width: 172px;
    display: block;
    padding: 4px 0 3px;
    }
    #tabs ul.tabNavigation a.selected{
    background-image: url("tab_click.gif");
    }
    #tabs ul.tabNavigation a span{
    padding: 0 10px;
    }
    #tabs div.tabbedWindow{
    padding: 10px;
    background-color: #ecf4f2;
    border: 1px solid #998b7d;
    }
    And finally, jQuery
    Now you only need the magic to get this clickable - and that's where jQuery jumps in. I use the PlaceHolderAdditionalPageHead to load the jQuery library and the JavaScript functions in the header of the page.





    That's all it takes to get it working. Smooth, easy and simple. And highly effective, I really like the way it works!

    Paging large content in SharePoint using jQuery

    The case
    Imagine you had a Publishing Page with a large chunk of content in the body (PublishingPageContent field for example). While you might just throw it to the users/visitors to read in one piece, it’s definitely much neater to split the content into pages.

    The requirements
    The only requirement posted by the author of the thread was that you should see the complete content while editing the page but have the paging enabled while in display mode.
    Looking at the above many different solutions appear on the horizon. To keep it simple and relatively lightweight I suggested using JavaScript for paging and a wrapper control to conditionally load the JavaScript (display mode only).
    The solution

    As I’ve already mentioned I’ve chose for JavaScript above servers-side controls to achieve the goal. In order to provide similar experience you would have to use AJAX, to display another page without an annoying postback.
    Working with JavaScript is not as straight-forward as we – .NET developers – would like it to be. Especially in such scenario as described above, when you have to obtain a piece of HTML, split it into chunks, and provide paging controls with the paging functionality. To simplify working with JavaScript I have decided to use jQuery – a powerful library which is being used in many web projects nowadays.
    Using the functionality that I have created, paging your own content comes down to entering the JavaScript snippet below:

    See it working live.
    The ins and outs
    I started off with breaking the whole thing into work items. I came up with the following list:
    Read the content of the given wrapper (eg. div)
    Split the retrieved content into chunks (eg. into paragraphs)
    Provide controls to display pages
    Display page based on the provided number of chunks per page
    Wrap it all in a class so it at least pretends to be reusable
    Retrieving content using jQuery and splitting it into chunks is really simple. The more-challenging part is to display the particular page and provide the paging controls.
    Using the chunks stored during the script initialization and the information about the number of chunks per page I came up with the following function:

    The showPage function takes one parameter: the number of the page you want to display (1-based). Because arrays in JavaScript are 0-based you have to subtract 1 from the page number to retrieve the proper items from the chunks array. Using a simple calculation (current page x number of items per page to (current page x number of items per page) + number of items per page) you can retrieve the right items from the array. There is one thing you have to consider however. Assuming you have 7 chunks with 3 chunks per page it gives you 3 pages. Using the calculation above you would try to retrieve the 8th item from the array which would result in an exception. To prevent it I have added a check which retrieves the items only if the index is lower than the number of chunks.
    Rendering the paging controls is quite straight-forward. Looping through the number of pages I add a list item with a link to the showPage function. The links are being added to all pages except the current so that you can easily track which page you are looking at.

    Accessibility
    The solution I have made uses the concept of progressive enhancement. The accessible POSH (Plain Old Semantic HTML) is being extended with JavaScript which provides the extra paging functionality. No matter whether you’re using an assistive technology, or having a JavaScript disabled the visitors are always able to get to the content.

    For more refer:http://blog.mastykarz.nl/paging-large-content-sharepoint-jquery/

    Using JQuery (client side JavaScript) to handle an ‘All’ option for SharePoint (edit)form checkboxes

    Sometimes there are easy solutions to easy problems. All it takes is a little thinking outside of the box.

    Prerequisites/knowledge:

    SharePoint: Intermediate
    HTML: Advanced
    JavaScript: Intermediate/advanced
    .Net: None
    Scenario:
    In a SharePoint entry form the user can select multiple values from a list. This should include an “All” option so in a long list the user can select or de-select all values with one click.

    So the interface should look like:
    Give this functional design to a SharePoint developer and he/she will come up with either:

    This is not possible with SharePoint
    This requires developing a new field control
    I’ll handle this server-side

    Another approach
    Let’s take a step back, forget SharePoint and just summarize what actions needs to happen (as if you instructed another human being to perform those actions)

    When the All option is clicked do:

    Is the All option checked?
    Then check all other checkboxes
    Else uncheck all other checkboxes
    That’s all!

    So put on your SharePoint cap again.
    These actions need to happen client-side (inside the browser).

    We want to attach a click handler to the All checkbox and when clicked it should toggle all the other checkboxes. (Note to self: there can be multiple groups of checkboxes on an entry form)

    If you have HTML & JavaScript experience you’re still with me and probably already thinking of a technical solution. Yes we need the _SPBodyOnloadWrapper here. And when you have (more then) some DOM experience you can attach code to the HTML INPUT tags.

    We’ll care about the How later. First lets analyze the HTML code SharePoint delivers and see how the checkboxes are defined.

    Let’s view the source of the entry/edit form.

    The HTML code Sharepoint generates


    I tidied the HTML a bit. As you can see every (input) checkbox has a unique id. We can fairly assume that SharePoint generates these so we can’t use hardcoded IDs. Now we need to come up with an approach to ‘execute’ Step 1

    “Then check all other checkboxes”

    Note that the IDs are all sequentially numbered; so apart from the last 2 digits all IDs (within one group) are the same.

    Basically we want to extend the INPUT tag of the All option with an extra JavaScript function



    The DOM battle plan:
    The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page.

    So with the DOM INPUT element for the All option we want to:

    IF an All option is clicked we want to:
    execute JavaScript code which:

    takes the ID of the clicked option

    cuts of the last 2 digits

    Uses that ID to toggle the other DOM elements.

    If you’re a programmer you’re already seeing the complex JavaScript manipulation of HTML DOM elements this takes.

    If you are not a programmer you probably don’t have a clue what I’m talking about… but do read on!

    Enter JQuery
    jQuery is a JavaScript library that helps you keep your code simple and succinct by addressing some of the complexities of Document Object Model (DOM) scripting and Ajax interaction. It helps you get right to the point and express yourself in the fewest possible characters and was initially created by John Resig in early 2006. It comes as a single JavaScript file with optional plugins containing all the common DOM, Event, Effects, and Ajax functions.

    With JQuery the JavaScript we have to add to the SharePoint page:

    $(”.ms-RadioText[title=’All’] :checkbox”).click(function(){
    var otherids = (this.id).substring(0, (this.id).length-2 );
    $(”input[id^=’”+otherids+”‘]”).attr( “checked” , (this.checked)?”checked”:”" );
    });

    YES! That’s all it requires. Sometimes a solution is as simple as the problem. Provided you use the right tools.

    This requires the JQuery JavaScript library. But I’m sure you can come up with similar code using MooTools or Sciptalicious. BTW the JQuery library is also used by Google and many other major sites.

    It’s (compressed) footprint is only 20k; compare that to the xxxK Microsoft SharePoint itsef loads in various supporting JavaScript libraries and you have to agree it’s a minimal but o so valuable extension to your SharePoint environment.

    Step by step
    $(”.ms-RadioText[title=’All’] :checkbox”).click(function(){

    JQuery selection of DOM objects which apply to the rules:

    Is class ms-Radiotext

    Which:

    Have the tile attribute ‘All’

    Which:

    Are of type: checkbox

    A function is attached to the Click event:

    var otherids = (this.id).substring(0, (this.id).length-2 );

    chops off the last 2 digits of the clicked (=this) identifier.

    $(”input[id^=’”+otherids+”‘]”).attr( “checked” , (this.checked)?”checked”:”" );

    The key here is the ^=

    This Jquery statement matches all DOM input elements which id attribute start with the given id

    It then sets the attribute “checked” to either “checked” or an empty string

    });

    Closes the function.

    Using it in SharePoint
    [to be extended]

    Add the JQuery.js library to a document library. Note the complte path to it
    Create a custom List ‘Vistted Continents’
    Create a column ‘continents’ with the values (including ‘All’)
    Open a New entry for the list
    Add a Content Editor WebPart to the NewForm page (how to: see Adding WebParts to Form pages (to be written))
    See: Google: ToolpaneView=2
    Paste in the code


    //Script Highlighter: http://tohtml.com/jScript/
    (The whole JQeury initialisation code can be placed in a MasterPage; that would bring the CEWP code to just the 3 lines of code)

    Additional notes:
    A SharePoint choice field can only store 255 characters; so the user gets a warning/error when the total number of characters for all selected values exceeds 255 characters!
    Must read JQuery references
    JQuery homepage
    http://www.jquery.com/
    Good examples can be found on other sites:

    JQuery (chainable events) examples
    http://codylindley.com/blogstuff/js/jquery/
    Simple JQuery examples
    http://markc.renta.net/jquery/
    50+ JQuery examples
    http://www.noupe.com/jquery/50-amazing-jquery-examples-part1.html
    45 even cooler examples
    http://outatime.wordpress.com/2008/03/06/45-fresh-out-of-the-oven-jquery-plugins/
    Rule library – manipulating CSS attributes
    http://flesler.webs.com/jQuery.Rule/

    Sunday, August 30, 2009

    SharePoint Data View Tricks

    More tricks for the sharepoint data view web part control for MOSS2007.

    So often times when making a new data view certain fields are too long to fit in the cell/div that you need it too. So here’s some XSLT I’ve been using to truncate a field.



                    <a href="@FileRef”> 
    
    <xsl:variable name="truncate-length” select="40”/>
    <xsl:value-of select="substring(@Title,1, $truncate-length)”/>
    <xsl:if test="string-length(@Title) > $truncate-length”>
    <xsl:text>...xsl:text>
    xsl:if>
    a>

    The above example runs inline, and grabs the URL and Title fields from a list item. It then truncates the Title to the length specified in the truncate-length variable to however many characters you want to use and then appends on ... to the end. Fairly straightforward but can be hard for some to build from scratch.

    Next, how to customize the built in [Current Date] field. Every time you make a filter off of [Current Date] an entry for it gets added in the code behind for the data view under the tag “SharePoint:SPDataSource”. The easiest way I’ve found to edit this field is to export it to notepad, or any basic text editor and replace the masked characters in it with the right ones

    & lt; = < 
    
    & gt; = >
    & quot; = "

    That will make it much easier to read

    <View>     <Query>         <Where>             <And>                 <Geq>                     <FieldRef Name="EventDate”/>                     <Value Type="Text”>                         <Today/>                     Value>                 Geq>                 <Leq>                     <FieldRef Name="EndDate”/>                     <Value Type="Text”>                         <Today OffsetDays="14”/>                     Value>                 Leq>             And>         Where>         <OrderBy>             <FieldRef Name="EventDate” Ascending="TRUE”/>         OrderBy>     Query> View>

    Unfortunately you can’t paste this much more readable code back in to sharepoint designer, but you can at least find where you need to edit it. In this case were looking for the Today tag after EndDate. I added the OffsetDays attribute and gave it a length of 14 days. You can also go negative for this value, so you can see things from previous times rather than future ones.