BPCUK 2011: Best Practices – Developer

Data Access from Code

– keep an eye on event throttling. SharePoint throws an unexpected error, if you try to receive more items than the allowed number: 5000

– use SPLongOperation to show the user the green in progress circle while doing an operations that takes longer time.

– things to consider when choosing the best option:

  • How to deploy? Farm vs Sandboxed Solutions
  • Where to run code? Server vs Client Code
  • How many items to return? Do you need to work with large return sets?
  • How important is developer productivity? Are IntelliSense and strongly-type access important?
  • – Server-side Code

  • Object Model – SPQuery
  • Object Model – SPSiteDataQuery
  • LINQ
  • – Client-side Code

  • SharePoint Client Object Model
  • Rest-based WebServices
  • Custom Web Service
  • Object Model

    – be aware of object disposal. Expose everything needed, but not too much. use SPDisposeCheck to check your disposal. Be awake that this tool does not always give correct feedback.

    – be aware how many items you want to retrieve. Do not retrieve more items than necessary

– be aware of item throttling

– there is a difference between SPList.Items.Count (all items, but no folders) and SPList.ItemCount (no all items, but folders)

– do not push against the SharePoint Boundaries

– always deploy using a solution file. The files stored on the file system are automatically populated to all WFE (even if new ones are added)

– be aware of where files are deployed, and might need to get retracted again

SPQuery

– Executes query against a single list, developer must parse together CAML fragments

– Query.QueryThrottleMode

    SPSiteDataQuery

    – Can execute query against multiple lists

– Query.QueryThrottleMode

– Query.webs (has a scope property)

– Query.ViewFields

– Be sure to properly test with production data, because all lists have to be walked through

    LINQ

    – Offers IntelliSense

– Does not provide more functionality than the Object Model. It is actually less, it only allows retrieval and edit of data, with code completion so that no more internal field names have to be used

– LINQ uses Extension Methods for adding additional functionality around the IEnumerable<T> collection

– Query Layout: Var query = from customer in dc.Customers Where customer.ID > 1

– Select clause can project an anonymous type: select new{surname = customer.LastName, FirstName = customer.FirstName}

– it is static (the Entity Model has to be updated to have changes made in SharePoint

– SPMetal creates Entity Classes and DataContext class

  • Each Entity Class represents a List in SharePoi
  • DataContext represents connection to sit – The Entity Model can be automatically updated via a command script, which can be included in the VS build. This way you will always have the latest Model Deployed

– Does not support throttling, no check in there. You have to manually make sure that you do not reach the limit

– LINQ queries are translated into CAML queries. Always check the generated query, e.g. for throttling (grouping is possible in LINQ, but not in CAML, thus first all data is loaded via CAML, then grouped via LINQ)

Client Object Model

– calls SP Foundation Object Model, thus no Server functionality available.

– No Context.Current.Web

– Explicit call to Execute, so reduction of server communication

REST

– Pay attention to security. It runs in _vti_bin, but for updates it is executed with the current user

– you can read the json file using JavaScript

– i think you can add a REST Service as a webservice to a VS project

Records Management

– there exists a DocID Feature for assigning a unique ID to a document, where ever it gets moved within SP

– try to use a separate Site Collection for Content Type Syndication

– Managed Metadata has support for multiple languages

– Content Organizer

  • Metadata-driven routing
  • Can target subfolders of destination library
  • Rule Manager User Group
  • In Theory, the rules should be managed by people that understand the documents, which is the "end-user". But he might not have the skills to manage rules – Email Routing Feature
  • Creates content type for emails
  • Creates drop-off library – In-Place Approach
  • Defines doc as record without moving it to a records center
  • Does not take advantage of features of the record center site
  • Lower cost (no need for record center)
  • Cannot apply location-based rules
  • More difficult to administer, because it docs are mixed with non-records – Repository Approach
  • Easier to administer
  • Harder to configure
  • Supports complex file plans
    • Location based policies
    • Metadata-driven rules
    • SharePoint in the Cloud (e.g Office 365)

      – use Sandboxed solutions

    – sandboxed solutions gets Resource Points assigned for their server usage, e.g. memory usage, CPU usage, for all sandboxed solutions together a maximum amount of Resource Points available is defined. When this limit is crossed, ALL solutions are disabled. Even after removing a solutions that would decrease the total amount again, you need to wait for a timer job to check everything again and enabled solutions. This timer job just runs once a day, I believe. So always check the Resource Points after deploying a sandboxed solutions.

Advantages:

(A1) they only run within the Site Collection for which they are deployed.

(A2) files are never store on the file system, but always in the content database

(A3) they use a separate process, and not the default SP process

Disadvantages:

(D1) only functionality allowed that does not cross site collections; no search, no user profiles, only limited API available. By using the client object model you can get around this issue, partly.

Solution Upgrade

– version number must always increase

– FeatureUpgrade Event, to define in code what and how to update

– Site Upgrade Feature, to define in XML what to upgrade, e.g. add column to content type

– important to think about what you want to update, all existing sites with that solution, just new ones, …

– in sandboxed solutions the filename must change, but the solution id must stay, the solution gallery then knows what to upgrade using the upgrade button

Solution Clean Up

– retraction of a solution does not remove anything that might cause data loss, like site definitions, content types or site columns

– use a feature receiver if you want to remove these too

Social Development

– there exists a SocialDataService to create and manage (NOT delete) social tags, ratings and comments) and to allow searching of these items in a url

Ribbon Development

– XML Customization

  • Do not remove OOTB controls
  • Always create your own group templates (copy-paste)
  • Provide multiple-layouts
  • Do not recreate existing controls
  • Use contextual tab groups
  • Only add customizations to the pages that need it

Ribbon Commands (a named object that performs an action)

– insert via Javascript and XML

  • Defined declaratively within the feature
  • Defined with xml
  • Execute and CanExecute portions defined within JavaScript – insert via Page Component
  • Defined entirely in a JavaScript object (in external js library)
  • Must be added to pages containing ribbon customizations
  • – insert via Page Component

  • Defined entirely in a JavaScript object (in external js library)
  • Must be added to pages containing ribbon customizations
  • – Command Types

  • Global: always available when on a page
  • Focused: only available at specific times, when designated by the page’s FocusManager
    • Try to avoid focused commands, they introduce complexity

    SilverLight Development

    – the load is completely on the client side, so you get no server load

    Event Receivers compared to workflows

    – it runs at the moment the event gets triggered and in the same http request

    – it has item delete events, (be aware that there are 3 ways of deleting an item)

Leave a Comment