#spstcdc just freakin work! development best practices in sharepoint

49
Just Freakin’ Work! Avoiding Common Hurdles in SharePoint Development Geoff Varosky (GraceHunt) Mark Rackley (Juniper Strategy) Welcome to SharePoint Saturday—The Conference

Upload: mark-rackley

Post on 15-Feb-2017

1.316 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Just Freakin’ Work!Avoiding Common Hurdles in SharePoint Development

Geoff Varosky (GraceHunt)Mark Rackley (Juniper Strategy)

Welcome to SharePoint Saturday—The Conference

Page 2: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference Welcome to SharePoint Saturday—The Conference

• Please turn off all electronic devices or set them to vibrate.• If you must take a phone call, please do so in the hall so as not

to disturb others.• Open wireless access is available at SSID: SPSTC2011• Feel free to “tweet and blog” during the session• Thanks to our Diamond and Platinum Sponsors:

Thank you for being a part of the first SharePoint Saturday conference

Page 3: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

About the speakers…• The Hillbilly

– Mr. Ackley• Catcher of all things that flow downhill• Solutions Architect for Juniper Strategy, LLC.

– www.juniper-strategy.com• Speaker, Blogger, (soon to be) Author• Blog: www.sharepointhillbilly.com• Twitter: @mrackley• E-mail: [email protected]

Page 4: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

About the speakers…• The Yankee

– Geoff Varosky• Director, Development and Evangelism• GraceHunt

– www.gracehunt.com• Speaker, Blogger, (soon to be) Author• Blog: www.sharepointyankee.com• Twitter: @gvaro• E-mail: [email protected]

Page 5: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

You might be a SharePoint Developer if…

Page 6: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Agenda• Introduction• Development• Deployment• Resources• Q&A

Page 7: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• Types of Development• Development Tools• Development Environment• Developing to Deploy

Page 8: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• Types of Development

– Unmanaged Code– Managed Code– Customization

Page 9: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• Development Tools

– STSDEV (2007)• stsdev.codeplex.com

– WSPBuilder (2007 & 2010)• wspbuilder.codeplex.com

– CKS:DEV (2010)• cksdev.codeplex.com

– SharePoint Designer– Developer Dashboard (2010)

Page 10: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• Development Environment

– Physical?– Virtual?– Desktop?– Dusty old PC under the desk?

Page 11: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• 2007 or 2010

– 64-bit (leaves room for upgrade)– >= 4G of RAM– Choice of Virtual Host

• HyperV, VMWare, VirtualBox• Not much in the way of VirtualPC support

– Create a base virtual image• SQL, Base SP install, Service Packs, Dev Tools• Visual Studio, SPD, etc.

Page 12: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• Development Environment

– Follow the SDK (2010)• 64 bit• Desktop

– Windows 7– Vista (SP1+)– Http://msdn.microsoft.com/en-us/library/ee554869.aspx

• Server 2008

Page 13: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• Development Environment

– Make sure your environment matches deployment targets!

• In Visual Studio– CPU

» x86? x64? AnyCPU?• .NET Framework• Service Packs• Same architecture

Page 14: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Introduction• Development Environment

– Don’t do everything as local admin!• Follow proper account configuration from the SDK

• Developing to Deploy– Use the least amount of privileges

• This will make admins happy– Web application deployment (/bin)

• CAS policies

Page 15: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• General Development Practices• Lists• Event Receivers• Web Parts• Unmanaged Code• Web Services

Page 16: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• General Development Practices

– Dispose of Objects!• SPDisposeCheck

– Test with multiple accounts/privileges– Strongly named assemblies– Separate high and low privileged DLLs– Do not mix .NET Framework versions– 64 bit code compatibility

Page 17: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• General Development Practices

– Stay away from the database• USE THE API!

– Use resource & language files• Do not hard code strings and labels

– Caching when and where possible• msdn.microsoft.com/library/bb687949.aspx

– CAS Policies– Safe Controls

Page 18: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• General Development Practices

– Use try{} catch{} finally{} blocks– Check for nulls in finally{} blocks with disposable

objects before disposing• Change defaults

– Assembly Info• Name it properly

– GraceHunt.SharePoint.WebParts.Stuff

Page 19: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• General Development Practices

– Sign Controls• Do not password protect the SNK

– Elevating Privileges• SPSecurity.RunWithElevatedPrivileges()

– Clean, Validated, Secure data– Runs as System account– Write operations?

» Preceeded by SPUtility|SPWeb.ValidateFormDigest– Must use new SPSite or SPWeb – not SPContext.Current

Page 20: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

You might be a SharePoint Developer if…

Page 21: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Lists

– Test queries before deployment!– U2U CAML Query Builder

• Remove the <Query></Query> tags!– http://www.spsprofessional.com/sqlcaml.aspx– LINQ– Batch queries when possible

Page 22: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Lists

– Do not use SPList.Items• Use SPList.GetItems(query)• Paginate (2000 items) – RowLimit

– GetItemByID• Use SPList.GetitemByID• Not SPList.Items.GetItemByID

Page 23: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Event Handlers

– Do not instantiate SPWeb, SPSite, SPList, or SPListItem

– Use what the properties give you• properties.OpenWeb()• properties.ListItem

– Bulk operations will not run event handlers• Ex: New list created – FieldAdding will not run

Page 24: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Event Handlers

– Connections• Make sure you code for external systems not being

available– LOG ERRORS

• Make it known why something went wrong

Page 25: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Web Parts

– Deploy to the Web Part Gallery• Easy to add to a page from there

– AllowClose = false• Closing web parts = bad• X DOES NOT EQUAL DELETE

– Use Properties – avoid hard coded values– HTMLEncode input values

Page 26: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Web Parts – In Code

– EnsureChildControls• Ensure that the controls have been loaded before using

them.

Page 27: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Unmanaged Code

– JavaScript• Will this be used in more than one place?• Central Script repository (easy access)• Deployment to _layouts folder

– More of a “managed” approach, more secure– Less flexible

Page 28: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Unmanaged Code

– Content Editor Web Parts• Awesome, flexible web parts!• Use a library with versioning to link the WP to

– Easier to manage– Versioning of “code”

– Publishing Sites• Use content controls, not CEWPs!

Page 29: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• Unmanaged Code

– Ghosted v. UnGhosted pages• Uncustomized v. customized• Unghosted pages can have issues with upgrades

– i.e. site definitions change with upgrades• Branding

Page 30: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SharePoint Web Services

– Provide remote access to a range of object model functionality

– Run on all front-end web servers– Heavily dependent on XML and CAML– Reside in physical file system in the \12\...

Directory and in a virtual file system in /_vti_bin

Page 31: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SharePoint Web Services – What They Do

– Provide programmatic access via .NET and SharePoint Designer

– Deliver relatively robust remote API functionality

– Expose SharePoint data repository to disconnected clients

Page 32: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SharePoint Web Services – What They Do

– Permit inter-farm communication (geographic distribution)

– Integrate well with WinForms, WPF, and SilverLight

– Client Object Model (SP 2010)

Page 33: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SharePoint Web Services – What they DON’T

do– Do not provide access to entire object model– Do not permit manipulation of BLOB objects

(documents)– NTLM and Basic Authentication Only– No SSO integration– No extensibility (sealed classes)– Limited data aggregation (no joins)

Page 34: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SharePoint Web Services – When to use them

– Remote accessibility– Integration with backend or legacy systems– Retrieval of items and content as XML– Perform large batch updates to lists

Page 35: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SPServices – jQuery library utilized SharePoint

Web Services– http://spservices.codeplex.com/

Page 36: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SharePoint Web Services Basics

– Add a Web Reference to any project type– Must specify existing SharePoint site in URL + “/_vti_bin/” +

ServiceName + “.asmx”– Set URL to dynamic

Page 37: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• SharePoint Web Services Basics

– All column names are XML encoded and prefixed with “ows_”

<rs:data ItemCount="1" xmlns:rs="urn:schemas-microsoft-com:rowset"> <z:row ows_Title="[email protected]" ows_MetaInfo="4764;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="4764" ows_owshiddenversion="5" ows_UniqueId="4764;#{2272A40C-0DA5-4C0D-938D-BFF3AF9C8ACF}" ows_FSObjType="4764;#0" ows_Created="2009-12-12 12:55:10" ows_FileRef="4764;#sps/Contact/test/Lists/Issues/4764_.000" xmlns:z="#RowsetSchema" /></rs:data>

Page 38: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

You might be a SharePoint Developer if…

Page 39: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• USE SOLUTION PACKAGES!• USE SOLUTION PACKAGES!• USE SOLUTION PACKAGES!• USE SOLUTION PACKAGES!• USE SOLUTION PACKAGES!• USE SOLUTION PACKAGES!• USE SOLUTION PACKAGES!• USE SOLUTION PACKAGES!

Page 40: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Development• User Code Solutions (2010 & Office 365)

– When possible– Forces better programming practices– Keeps the farm safe

• Makes admins & managers happy– Admins can control

• Makes them feel special

Page 41: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Resources• Development Tools

– Codeplex.com• Search SharePoint & Development

– SharePointDevWiki.com• www.sharepointdevwiki.com/display/public/

SharePoint+Development+Tools– SPDisposeCheck

• code.msdn.microsoft.com/SPDisposeCheck

Page 42: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Resources• SDKs

– 2010• Server and Foundation

– http://msdn.microsoft.com/en-us/library/ee557253.aspx

– 2007• WSS

– http://msdn.microsoft.com/en-us/library/ms441339(office.12).aspx

• MOSS 2007– http://msdn.microsoft.com/en-us/library/

ms550992(office.12).aspx

Page 43: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Resources• General Development

– Roger Lamb’s Blog• blogs.msdn.com/rogerla/

– Patterns & Practices SharePoint Guidance• msdn.microsoft.com/en-us/library/dd203468.aspx

– Using Disposable Objects• msdn.microsoft.com/en-us/library/

aa973248(v=office.12).aspx

Page 44: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Resources• General Development

– Working with Large Lists• go.microsoft.com/fwlink?LinkId=95450

– SharePoint 2007 Best Practices Resource Center• technet.microsoft.com/en-us/office/sharepointserver/

bb736746.aspx

Page 45: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

You… BEFORE session…

Page 46: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

You… AFTER our session…

Page 47: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Resources

Q&A

Page 48: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Thanks to Our Other Sponsors!Thanks to our Sponsors

Page 49: #SPSTCDC Just Freakin Work! Development Best Practices in SharePoint

Welcome to SharePoint Saturday—The Conference

Session EvaluationPlease complete and turn in your Session Evaluation Form so we can improve future events. Survey can

be filled out at:

http://app.fluidsurveys.com/surveys/spstc2011- and add the Session number to the URL

Presenter: Geoff Varosky & Mark Rackley

Session Name: Just Freakin’ Work!Session No.: FRI-S5A-110