slide1 n.
Skip this Video
Download Presentation
Reza Alirezaei , SharePoint MVP /MCTS Development Horizon, Corp. Twitter: @ rezaal

Loading in 2 Seconds...

play fullscreen
1 / 38

Reza Alirezaei , SharePoint MVP /MCTS Development Horizon, Corp. Twitter: @ rezaal - PowerPoint PPT Presentation

  • Uploaded on

Reza Alirezaei , SharePoint MVP /MCTS Development Horizon, Corp. Twitter: @ rezaal. Turning Chaos into Order: Best Practices for Developing SharePoint Applications. Who am I?. Microsoft MVP SharePoint (2007, 2008) SQL Server Reporting Services (2006)

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Reza Alirezaei , SharePoint MVP /MCTS Development Horizon, Corp. Twitter: @ rezaal' - melangell

Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Reza Alirezaei , SharePoint MVP /MCTS

Development Horizon, Corp.

Twitter: @rezaal

Turning Chaos into Order:

Best Practices for Developing SharePoint Applications

who am i
Who am I?

Microsoft MVP

SharePoint (2007, 2008)

SQL Server Reporting Services (2006)

Microsoft Certified Technology Specialist

MOSS 2007 Configuration

MOSS 2007 Application Development

Top 20 Contributor to MSDN Wiki 2006, 2007,2008

International SharePoint Professional Association Regional Evangelist (Canada)


Enterprise level SharePoint application

Large scale Integration Projects


Dev Tooling Experience




Some Architectural Decisions



  • Good Understandings of SharePoint Dev
  • Definitely Not a 101 session
why do i care
Why do I care?

Anti best practices:

“I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.”

Abraham Maslow

sharepoint uber dev tools
SharePoint Uber Dev Tools
  • Most Popular Tools
    • WSPBuilder (Community)

    • STSDEV (Community)

    • VSeWSS (Microsoft)

    • Old School way
  • Microsoft endorsement on VSeWSS
  • Cleanup code is your responsibility
  • Quick Overview of all three tools
  • VSeWSS Solution Generator
    • VSeWSS WCF endpoint
configuration management strategy
Configuration Management Strategy
  • Four most common solutions:
    • Settings in Solution Manifiest
    • SPWebConfigModification class
    • SharePoint List
    • Configuration From Web Services
    • Property bags (SPWebApplication.Properties)
  • SPWebConfigModification’s Top 6 Issues

  • Scope at Web Application, not Site collection
  • Note: Persisted attributes in SPPresistedObject class as BLOB XML
execution in parallel is king
“Execution in Parallel” is King!
  • ONLY one slow Web Part… ONLY one slow Process….
  • No ASP.NET Async Luxury
    • No Async Page Directive
    • How many Web Parts on one page
    • How many instances of your Web Part on one page
  • So, what are my *pure SharePoint* options?
    • Create a Worker Class to handle Async code
    • SPLongOperation Class
    • Use Built-in Functionalities
      • -ed Event handlers
      • Workflows
      • CQWP
      • DFWP
workflow or event handler
Workflow or Event Handler?


Event Receiver






Running > 5 min


High Volume



Asynchronous Dev

memory leaks
Memory Leaks
  • MSDN Paper

  • Roger Lamb’s Blog

  • . Net Rule for Disposing Objects
  • Edge –Cases!!
  • SPDisposeCheck

edge case 1
Edge Case -1

public class MyFeatureRec : SPFeatureReceiver{

public override void FeatureActivated(SPFeatureReceiverProperties properties)


//Does the following reference to SPSiteleak?

SPSitesite = properties.Feature.Parent as SPSite;



edge case 2
Edge Case -2

public class MyClass: SPItemEventReceiver{

public override void ItemUpdated(SPItemEventProperties properties)


//Does the following reference to SPWeb leak?

SPWebweb = properties.OpenWeb();



edge case 3
Edge Case -3

public class MyClass: SPWebProvisioningProvider{

public override void Provision (SPWebProvisioningPropertiesprops)


//Does the following reference to SPWebleak?

SPWebweb = props.Web;



my 0 02
My $0.02
  • Don’t Dispose in Edge Cases
  • SPDisposeCheck
  • Edge Cases
how about this one
How about this one?

SPWeboWeb = SPContext.Current.Web;

//Does the following reference to SPSite leak?

SPSiteoSite = oWeb.Site;

Say No To Disposing Of objects hanging off SPContext


MOSS is a Ecological System


Custom WPs/Procs


All of these technologies must fit in a single 32-bit process










CRL/Native APIs



x64 issues
x64 Issues

x86 Issues

  • Last slide + A lot more issues!

Go hybrid & Build “ Any CPU”

  • Artifact/WP development - don’t matter
  • Protocol handlers/iFilters/ Document Convertors
  • Many of the current dev tools run in WOW
  • Some tools don’t support x64 bit (STSDEV)
  • Infrastructure Cost
  • Not ISV friendly
  • VS 2008 WF Templates (Seq and State) not supported, but who cares?!
app pool best practices
App Pool Best Practices
  • Say No to Web Gardening
    • Not supported
    • Breaks Blob Cache (Wrong Header)
  • Leave App pools in Legacy Mode (a.k.a worker process isolation mode)
  • Most of the time , leave App Pool settings as it is
  • Stick to reasonable upper bounds of RAM utilization (850 Mb on x86 or 1.2Gb on x64)
list capacity planning
List Capacity Planning

Working with Large List Paper MSDN

Recap of the MSDN paper on my blog

Bottom Line is :

2000 items per list limit is …..

SPList w/DataTable or SPList w/for/each ……..

Escalation of SQL Server Lock on Lists Table is serious

Be cautious about using Collections & Avoid Using Indexes on each Call

properly working with collections
Properly Working With Collections

// BAD way

SPWeb web = SPContext.Current.Web;

string tasksID = web.Lists[“Tasks”].ID;

string tasksTitle = web.Lists[“Tasks”].Title;

// GOOD way

SPWeb web = SPContext.Current.Web;

SPListtasksList = web.Lists[“Tasks”];

string tasksID = tasksList.ID;

string tasksTitle = tasksList.Title;

what is wrong with this code
What is wrong with this code?

SPListbigList = web1.Lists[“BigList”];

foreach(SPListItem item in bigList.Items)


if(item[“MyColumn”] == “Foo”)


Console.WriteLine(“Found One!”);



working with splist
SPList.Items gets a collection with ALL list items

Terrible for big lists

Lots of memory needed

Lots of SQL I/O

Lots of network

Lots of CPU

Instead use SPList.GetItems

Takes a CAML query

Working with SPList

Say No To

Content Query Web Part (QueryOverride Prop)

Data Form Web Part with FullTextSqlQueryObject


Primarily used for navigation controls

Optimized to query data not only across lists, but across webs

Scope limited to the current site collection

Limitations :

Not good for infrequent queries

Not good for frequently changed data

Uses the same shared caching facility in your site collection


avoid reporting directly off of sharepoint databases
Avoid Reporting directly off of SharePoint Databases

Use OM

Web Services

RPC Calls (Remote)

Use innate capability of your reporting tool

Lists or Database?

  • Reporting against Lists
  • Aggregating of Content
security is not a joke
Security is NOT a Joke
  • Know your threat model and what security context your code runs on behalf of.

  • GAC or BIN?
    • Event Receivers
    • Workflows
    • Provision Handlers
    • Web Parts if they’re being manipulated programmatically
  • permcalc -Show <assemblyName> utility in .Net Framework 2.0

  • NEVER raise the trust level in Web.config to FULL – NEVER!
  • System Account = Application Pool Identity
  • Elevation of Privilege – do it the right way!

Elevating the security context *Properly*

think farm not standalone
Only WSP deployment , but….

Use timer Jobs to Sync up thing in your entire farm


Don’t touch file system on a server directly

Don’t touch file system by System.IO either

Don’t use LOCK in timer jobs if targeting the farm

Think Farm, NOT Standalone

System.IO Love

(Well, not really!)



  • Professional SharePoint 2007 Web Content Management Development by Andrew Connell
  • Francis Cheung (Microsoft patterns & practices)
  • Patterns & Practices SharePoint Guidance
last but certainly not least
THINK SHAREPOINTLast but certainly not least: