Wednesday 14 July 2010

SP2010 CQWP customisation

Overview: Content Query Web Part (CQWP) in SP2010 is similar to in MOSS. This post walks thru using the CQWP to display a custom list and custom columns while outputting custom html via a custom xslt.
CQWP (need the publishing feature enabled, this creates the styles library and add the CQWP) by default uses the xslt /Style Library/XSL Style Sheets/ItemStyle.xsl.

Steps:
  1. Don't write over ItemStyle.xsl as this si supplied by SP2010 OOTB. Rather create a new xslt and put it into the styles library. Build up the xslt, I based my file on the itemstyle.xsl file, see rules for getting the output you are looking for using How to: Customize XSL for the Content By Query Web Part
  2. Custom xslt formatting, I always add the following code in case I want to see what the available fields are:
  3. Deploy the custom style sheet via a feature.
  4. Create a new Custom list called "Pets" and add columns for Title, Age & Status (choice):
  5. Edit your custom xslt to display for "Pets" as shown below:
  6. Add a new CQWP to your page. Configure it to display items from your new list (Pets).
  7. Change the "Presentation" section, "Item Style" to Show "Pets". Apply the Changes:
  8. CQWP displays as:
  9. Edit the CQWP "Age" property to "Age"
  10. Edit the CQWP "Age" property to "Status"

    Tuesday 13 July 2010

    Audience Targeting in SP2010

    Overview from MS
    Technet User Profile Service Overview
    Audience targeting needs compilation so not useful when adding users on 1st login however, menu items can be targeted using SharePoint security groups.
    Audience targeting is part of SharePoint Standard edition.  SharePoint 2010 editions comparison.
    Update 5 Dec 2010 - The "Publishing feature" needs to be enabled on the site collection and site.  User Profile Service needs to be running.

    Setup Audience targeting on Global menu's.

    Overview: To use audience targeting you need to have at least SharePoint Server standard edition as you need the "Site Collection Publishing Feature" enabled. 

    In this walk thru I am adding a user to a SharePoint Group and allowing the group to see a menu option.  Also ensure audience targeting is enabled.
    Add the user to the Share Point group in my case I added the user "ReadOnlyUser" to SharePoint Security group "Extend Visitors".
    Edit the menu option to be only visible to the SharePoint group "Extend Visitors".
    Menu of normal user without the extra menu option.
    User that can see additional menu options

    Monday 12 July 2010

    Sharepoint 2010 Dialogs Framework

    Problem: Use the dialog framework to edit information on a SharePoint composite page.
    Hypothesis: Dialog framework can open existing pages and pass back values to the calling page. The pass back value can be more than just a simple parameter such as a string. You can return fairly complex flat objects. The example below, displays multiple addresses, allows the user to edit any of them via a modal dialog. and returns the updated address along with the id of the element address to change. To use the dialog framework modals you need SP context so use any of the client OM's or the server OM (i.e. you can't use html unless to load the SP context)
    In the parent page inside javascript add the following 2 functions
    function OpenDialogAdr(myurl) {
    var options = SP.UI.$create_DialogOptions();
    options.url = myurl;
    options.width = 200;
    options.height = 100;
    options.dialogReturnValueCallback = CloseCallback;
    var dialogSP = SP.UI.ModalDialog.showModalDialog(options);
    }
    var messageId;
    function CloseCallback(dialogResult, returnValue) {
    if (dialogResult === SP.UI.DialogResult.OK) {
    var adr = returnValue.adr;
    var id = returnValue.id
    $("#adr-sales-" + id).html(adr);
    }
    }


    Add a link with the appropriate js:
    Add the child page, that will return the new address and the id of the item to change.

    function onUpdate() {
    var adrs = document.getElementById('txtAdr').value;
    var ids = document.getElementById('txtId').value;
    var mydata = {
    adr: adrs,
    id: ids
    };
    SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, mydata);
    }
    function onCancel() {
    SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult
    }

    Resolution:
    The dialog framework is good for displaying additional information. It is similar in nature to using jQuery & the lightbox plug in.

    Resources:
    Working with SP2010 modal dialogs

    SharePoint 2010 UI/browser help urls

    Site settings url: http://...../_layouts/settings.aspx
    Determine CAML to create site columns  http://url/_vti_bin/owssvr.dll?Cmd=ExportList&List=listguid
    Remove web parts from a page http://url/_layouts/spcontnt.aspx?&url=page/_layouts/spcontnt.aspx?&url=page

    VS2010 deployment error Site Url property missing

    Overview: Each new developer on a project grabs the solutions/project files from TFS or VSS as in my case. When they try deploy the solution, they receive an error "Error occurred in the deployment step 'Recycle IIS Application pool': Cannot connect to the SharePoint Site: http://... Make sure that this is a valid URL and the SharePoint site is running on the local computer, ... Update the Site URL property on the project."
    Resolution: As the error suggest go to the project being deployed and ensure that you local development url is entered in the "Site URL" property. Obviously this setting should not be stored in source control as it will often differ per environment/developer.
    Visual Studio 2010 Project properties

    Friday 2 July 2010

    Dynamic LINQ to SharePoint 2010

    Problem: I have 2 connected Web Parts, the provider provide multiple values for lookup columns. I started with LINQ to SharePoint (SPMetal) but could not build up the query dynamically.
    Hypothesis: My initial reaction was to use a dynamic CAML query as done in MOSS using U2U to work out my query. The issue is that the CAML is not safe (as we don't get validation until run-time) but at least I can dynamically build up my query.

    Using Dynamic link with LINQ to SharePoint to can achieve the required result. The code is safe as least for run-time (my logic is still dodgy). Only issue is with the performance and the results if the list if large. Using a very broad LINQ-to-Sharepoint query that is converted into a CAML query anyway I get a large result set. I then filter using dynamic LINQ. Pretty heavy filtering and inefficient querying. Throttling concern: If I returned more than 5,000 items (default list throttling limit for SP2010 lists) I now loose results that should be queried (SharePoint would trim my SPMetal query and then Dynamic LINQ would work on the max of 5,000 items). Sure you can turn throttling off as a farm admin but not a great idea. You could programatically override the throttling (SPQueryThrottleOption.Override) using the server OM but this doesn't help for your SPMetal query.
    In this case, my best option is to use a dynamic CAML query and get the exact set of data I am looking for.

    Tip: Only get the fields you are using in CAML queries.
    More Info:
    Building CAML queries
    Dynamic LINQ - Scott Guthrie

    LINQ to SharePoint Posts

    Thursday 1 July 2010

    Installing Sharepoint 2010 options & Basic SP2010 manual installation tips

    You have 4 options for installing SharePoint farms:
    1. Manually sun the setup and follow the installation wizard (this is discussed below);
    2. Deploy SharePoint 2010 via a slipstream install, this was my prefered method for MOSS.  I ran the install from a batch file that got it's configuration from an xml file;
    3. PSConfig installation (sic); or
    4. Use PowerShell to Install SharePoint. and technet scripted deployment
     Summary: For environments such as live the PowerShell/Slipstreamed options are best as they allow for recreation and input is always identical.  Manual install is fine for development servers however their is no advantage except for a lower learning curve for the IT admin.
    Post below is a Manual Installation:
    SP2010 install video
    Install the pre-requisites
    • Prerequisits will install roles and software you need internet access on the server to fetch the prerequisits software (this can be put on the server to stop the machine going to the Internet).
    • Preferably have seperate instance of SQL 2008 R2 but for dev/demo machines. If 1 machine rather setup SQL devleoper or a instance (I dislike using SQL express).
    Setup / SP 2010 install tips
    • Install "Server farm" option not standalone
    • "Complete" installs all component prefered option
    • Connect to a new farm
    • Database server name us name rather than IP (incase it changes)
    • DB account (must already exist in AD)
    • Passphrase used to connect new servers to this server farm (remeber/keep it)
    • Kerbros - if your network supports it but use NTLM if you aren't sure.
    • Wizard - follow screens, services can be heavy so add them when you need them, however for demo I select all services and create a new site collection - a good options is to use the Team Site Template.
    • Need 3 accounts for min Best practices: 1) Managed Service account (domain user account) that SQL Server runs in, 2) Managed Service Account (domain user account) all services will be installed on this account (MS suggests using a seperate managed account for each service) on small farm s/dev I use 1 account,  and 3) Farm install account (domain account) this needs to be a local admin on each SP2010 server and have creator & dbsecurity accouts on SQL.
    • 5 Accounts is a better option excluding the SQL services account namely:
    1. SP-Install - domain account with admin local rights on each WFE also need SQL dbcreator and securityadmin roles (used to login and install binaries, use this account for add new servers to the farm),
    2. SP-Farm - domain account no permissions, will be the account to run timer job and other key roles,
    3. SP-Web-App-Pool - Content Web app account - Domain account only,
    4. SP-Services - Install all services to use the same domain account, this can be seperate for each services but for easy of setup and mainentance use 1 account.  Exception is the User Profiles service, setup seperately using Spence Harbors post as the user domain account needs unique security, and
    5. SP-Crawl - Used to crawl SP content.
    Additional Info on accounts:
    1. SQL Server needs to run as a windows service, you need an account, I would use a managed account in AD with no permissions called SP2010-SQLService.
    2. Farm Installation account, you need to create a domain user account in AD, give the account local admin access to each SP2010 machine.  Call it SP2010-Admin.
    3. SP2010 Service account/s, you need to create a managed service account with zero permissions in AD.  You can use 1 account or create a seperate account for each service (MS Best Practice).  I call my 1 account SP2010-Services. 
    Use slipstreaming for SharePoint it's faster and consistant.
    Use:
    1. Windows 2008 R2 x64
    2. SQL 2008 x64
    3. On HyperV/VMWare except the db which should be a seperate physical machine/SAN
    Update 08 November 2010:  Notes on deploying a 3 server farm consisting of 2 WFE's that are NLB using Windows NLB.  Installation done using AutoSPInstaller. 
    Installation Notes for a 3 server NLB SharePoint 2010 farm

    Update 10 November 2010: SharePoint install account - Todd Klindt.
    Update 11 May 2011: SharePoint 2010 database management article