Top Banner
Just Freakin’ Work! Avoiding Common Hurdles in SharePoint Development Geoff Varosky Mark Rackley
46

Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Nov 21, 2014

Download

Technology

Geoff Varosky

ession presented with both Geoff Varosky and Mark Rackley.

"Why am I getting a security error?" "Why does my code work sometimes, but not others?" "I wonder if McDonalds is hiring." Writing custom code in SharePoint opens up unlimited possibilities but also throws many hurdles in your way that will slow you down if you don’t take them into account. So, before giving up and searching for careers in the fast food industry, equip yourself with the knowledge you need to succeed in writing custom code for SharePoint.

In this session you will learn:

- Best practices for avoiding performance issues
- Best practices for avoiding memory leaks
- Best practices for elevating privileges
- Avoid not disposing of SP Objects
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Just Freakin’ Work!Avoiding Common Hurdles in SharePoint

Development

Geoff VaroskyMark Rackley

Page 2: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

About the speakers…

The HillbillyMr. Ackley

Catcher of all things that flow downhillSolutions Architect for Juniper Strategy, LLC.

www.juniper-strategy.com

Speaker, Blogger, (soon to be) AuthorBlog: www.sharepointhillbilly.comTwitter: @mrackleyE-mail: [email protected]

Page 3: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

About the speakers…

The YankeeGeoff Varosky

MCP, MCTS

Senior Solutions Developer for Grace-Hunt, LLC.

www.grace-hunt.com

Speaker, Blogger, (soon to be) AuthorBlog: www.sharepointyankee.comTwitter: @gvaroE-mail: [email protected]

Page 4: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

You might be a SharePoint Developer if…

Page 5: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Agenda

IntroductionDevelopmentDeploymentResourcesQ&A

Page 6: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

Types of DevelopmentDevelopment ToolsDevelopment EnvironmentDeveloping to Deploy

Page 7: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

Types of DevelopmentUnmanaged CodeManaged CodeCustomization

Page 8: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

Development ToolsSTSDEV (2007)

stsdev.codeplex.com

WSPBuilder (2007 & 2010)wspbuilder.codeplex.com

CKS:DEV (2010)cksdev.codeplex.com

SharePoint Designer

Page 9: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

Development EnvironmentPhysical?Virtual?Desktop?Dusty old PC under the desk?

Page 10: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

2007 or 201064-bit (leaves room for upgrade)>= 4G of RAMChoice of Virtual Host

HyperV, VMWare, VirtualBoxNot much in the way of VirtualPC support

Create a base virtual imageSQL, Base SP install, Service Packs, Dev ToolsVisual Studio, SPD, etc.

Page 11: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

Development EnvironmentFollow the SDK (2010)

64 bitDesktop

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

Server 2008

Page 12: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

Development EnvironmentMake sure your environment matches deployment targets!

In Visual StudioCPU

x86? x64? AnyCPU?

.NET FrameworkService PacksSame architecture

Page 13: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Introduction

Development EnvironmentDon’t do everything as local admin!

Follow proper account configuration from the SDK

Developing to DeployUse the least amount of privileges

This will make admins happy

Web application deployment (/bin)CAS policies

Page 14: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

General Development PracticesListsEvent ReceiversWeb PartsUnmanaged CodeWeb Services

Page 15: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

General Development PracticesDispose of Objects!

SPDisposeCheck

Test with multiple accounts/privilegesStrongly named assembliesSeparate high and low privileged DLLsDo not mix .NET Framework versions64 bit code compatibility

Page 16: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

General Development PracticesStay away from the database

USE THE API!

Use resource & language filesDo not hard code strings and labels

Caching when and where possiblemsdn.microsoft.com/library/bb687949.aspx

CAS PoliciesSafe Controls

Page 17: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

General Development PracticesUse try{} catch{} finally{} blocksCheck for nulls in finally{} blocks with disposable objects before disposing

Change defaultsAssembly Info

Name it properlyGraceHunt.SharePoint.WebParts.Stuff

Page 18: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

General Development PracticesSign Controls

Do not password protect the SNK

Elevating PrivilegesSPSecurity.RunWithElevatedPrivileges()

Clean, Validated, Secure dataRuns as System accountWrite operations?

Preceeded by SPUtility|SPWeb.ValidateFormDigestMust use new SPSite or SPWeb – not SPContext.Current

Page 19: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

You might be a SharePoint Developer if…

Page 20: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

ListsTest queries before deployment!U2U CAML Query Builder

Remove the <Query></Query> tags!

http://www.spsprofessional.com/sqlcaml.aspxLINQBatch queries when possible

Page 21: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

ListsDo not use SPList.Items

Use SPList.GetItems(query)Paginate (2000 items) – RowLimit

GetItemByIDUse SPList.GetitemByIDNot SPList.Items.GetItemByID

Page 22: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

Event HandlersDo not instantiate SPWeb, SPSite, SPList, or SPListItemUse 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 23: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

Event HandlersConnections

Make sure you code for external systems not being available

LOG ERRORSMake it known why something went wrong

Page 24: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

Web PartsDeploy to the Web Part Gallery

Easy to add to a page from there

AllowClose = falseClosing web parts = badX DOES NOT EQUAL DELETE

Use Properties – avoid hard coded valuesHTMLEncode input values

Page 25: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

Web Parts – In CodeEnsureChildControls

Ensure that the controls have been loaded before using them.

Page 26: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

Unmanaged CodeJavaScript

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

More of a “managed” approach, more secureLess flexible

Page 27: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

Unmanaged CodeContent Editor Web Parts

Awesome, flexible web parts!Use a library with versioning to link the WP to

Easier to manageVersioning of “code”

Publishing SitesUse content controls, not CEWPs!

Page 28: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

Unmanaged CodeGhosted v. UnGhosted pages

Uncustomized v. customizedUnghosted pages can have issues with upgrades

i.e. site definitions change with upgrades

Branding

Page 29: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SharePoint Web ServicesProvide remote access to a range of object model functionalityRun on all front-end web serversHeavily dependent on XML and CAMLReside in physical file system in the \12\... Directory and in a virtual file system in /_vti_bin

Page 30: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SharePoint Web Services – What They Do

Provide programmatic access via .NET and SharePoint DesignerDeliver relatively robust remote API functionalityExpose SharePoint data repository to disconnected clients

Page 31: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SharePoint Web Services – What They Do

Permit inter-farm communication (geographic distribution)Integrate well with WinForms, WPF, and SilverLightClient Object Model (SP 2010)

Page 32: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SharePoint Web Services – What they DON’T do

Do not provide access to entire object modelDo not permit manipulation of BLOB objects (documents)NTLM and Basic Authentication OnlyNo SSO integrationNo extensibility (sealed classes)Limited data aggregation (no joins)

Page 33: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SharePoint Web Services – When to use them

Remote accessibilityIntegration with backend or legacy systemsRetrieval of items and content as XMLPerform large batch updates to lists

Page 34: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SPServices – jQuery library utilized SharePoint Web Services

http://spservices.codeplex.com/

Page 35: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SharePoint Web Services BasicsAdd a Web Reference to any project typeMust specify existing SharePoint site in URL + “/_vti_bin/” + ServiceName + “.asmx”Set URL to dynamic

Page 36: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

SharePoint Web Services BasicsAll 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 37: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

You might be a SharePoint Developer if…

Page 38: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

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 39: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Development

User Code Solutions (2010)When possibleForces better programming practicesKeeps the farm safe

Makes admins & managers happy

Admins can controlMakes them feel special

Page 40: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Resources

Development ToolsCodeplex.com

Search SharePoint & Development

SharePointDevWiki.comwww.sharepointdevwiki.com/display/public/SharePoint+Development+Tools

SPDisposeCheckcode.msdn.microsoft.com/SPDisposeCheck

Page 41: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Resources

SDKs2010

Server and Foundationhttp://msdn.microsoft.com/en-us/library/ee557253.aspx

2007WSS

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

MOSS 2007http://msdn.microsoft.com/en-us/library/ms550992(office.12).aspx

Page 42: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Resources

General DevelopmentRoger Lamb’s Blog

blogs.msdn.com/rogerla/

Patterns & Practices SharePoint Guidancemsdn.microsoft.com/en-us/library/dd203468.aspx

Using Disposable Objectsmsdn.microsoft.com/en-us/library/aa973248(v=office.12).aspx

Page 43: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Resources

General DevelopmentWorking 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 44: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

You… BEFORE session…

Page 45: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

You… AFTER our session…

Page 46: Just Freakin' Work - Overcoming Hurdles and Avoiding Pain

Resources

Q&APlease be sure to fill out your

session evaluation!