best practices configuring and developing share point solutions
DESCRIPTION
This presentation contains best practices from myself and Microsoft regarding configuring and developing SharePoint Solutions. What to do with development, resources, disposing, deployment and some other items.TRANSCRIPT
Alexander Meijers &
Roel Hans Bethlehem
Introduction
Alexander Meijers
• Architect at Sparked• Subject matter Expert for
SharePoint and Search• http://www.bloggix.com/blogs/
microsoft• http://www.dutchsug.nl
Roel Hans Bethlehem
• Architect at Sparked• Subject matter Expert for
SharePoint
Agenda
• Project & tools• Keep to the Basics• Locations• Permissions• Development• Styling• Multilanguage• Deployment
Setup a development project• Create single solution• Add for each namespace in your project a class library
project• Create a namespace for deployment• Create a duplicate tree of the 12 Hives• Make use of tools like
– Add in for WSP Builder (http://www.codeplex.com)– SharePoint installer (http://www.codeplex.com)
• Use features– Installing components– Changes to config files
Tools• WSPBuilder
– Creates SharePoint Solutions files based on a folder structure
– Deploy solutions
• SharePoint Installer– Creating user friendly installation and deployments for SharePoint 2007
solutions
• VSeWSS 1.2– Visual Studio 2008 extensions
• STSDEV– Generate Visual Studio project files and solution files
• STSADM– 184 operations through command line on the web server
– Custom extensions possible
Demo
Tools & Project setup
Keep to the basics
• Use standard functionality as much as possible– All SharePoint functionality out-of-the-box will
still work like search, versioning and publishing
• Use SharePoint as storage
• Powerful API model
• Do not change or replace existing files
Master pages, layouts, CSS, images, scripts
• Into a library inside your site collection– Can be referenced by ~site, ~sitecollection and ~masterpage
– Only available within the site collection
– Too many site collection makes it harder to update these files
– Updatable through the web interface
• Into the _LAYOUTS folder– Can be referenced by path to folder
– Available for every Sharepoint website in farm
– One place for easy updating these files
– Only updatable directly on the server
– All web applications on the server share this folder
Code Access Security
“Request for the permission of type Microsoft.SharePoint.Security.SharePoint
Permission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c failed”
Code Access SecurityWhat is it?
• Security model use by the SharePoint API• Ensure your code provides error handling in the event
that required permissions are not available• Arrange Web applications to operate in a partially trusted
environment– System.Security. AllowPartiallyTrustedCallersAttribute()
• Level of trust– Full, High, Medium, Low, Minimal – Custom like WSS_Minimal, WSS_Medium
Code Access SecurityWhat are the options?
• Decorate your code with Request Permissions– Declarative Security like
[SomePermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
• Deployment and CAS– Trustlevel in your web.config– GAC– Custom policy file
• Snippet: <PermissionSet class="NamedPermissionSet"
version="1"
Name="SPRestricted">
<IPermission
class="AspNetHostingPermission"
version="1"
Level=“Medium"
/>
</PermissionSet>
Custom policy example
Permissions Who am I?
• Your code runs with permissions of the logged on user
• Set up proper testing– Especially for anonymous internet facing sites– I always use Firefox since it does not log me on
• Coding & Elevation– Impersonation– SPSecurity.RunWithElevatedPrivileges
Demo
Elevation
Web Part development
• Do not use any code in your Web Part• Always load an UserControl
– Use the ControlTemplates folder– Put the logic into the control– Code and design should be separated
• Put only properties in your Web Part• Two namespaces
– System.Web.UI.WebControls.WebParts– Microsoft.SharePoint.WebParts
Web Part development• Think of
– Show only accessible / all content– Check if content is published or not– Recursive reading SPWeb objects
• UX & Design– AJAX– Silverlight– SharePoint objects like
EditorPart & EntityEditorWithPicker
Demo
Web Part Development
Dispose or not to dispose?
Two objects in the API model which needs to be disposed of– SPSite– SPWeb
• Dispose only when created yourself by– SPSite site1 = site2;– Use method Dispose() with try, catch, finally– or using(…) {…}
• Do not dispose contextual objects– SPContext.Current.Web.Dispose();
• Tool SPDisposeCheck
Demo
Dispose or not to dispose?
Styling, what are the options?
• CSS stylesheet reference (configurable)• Own site definitions, masterpages and templates
– Separation of layout and content– Full control– ONET.XML editing
• Themes– Different styles en color schemes for users (only reason to use it!)– Testing your theme is terrible
• Schema files for lists– CAML knowledge required– Full control of list layout
Styling, what are the options?
• Use Firefox with the “Web developer” add on– Easy retrieval of styling
– Enabling / Disabling certain elements
– Visualizing your divs and tables
• Accessibility– Out-of-the-box is not conform standards
– Accessibility Kit for SharePointhttp://aks.hisoftware.com/index.html
• Resources– Heather Solomon
http://www.heathersolomon.com/
– SharePoint Branding Toolhttp://www.codeplex.com/BrandingTool
Demo
Enabling a theme with a feature
Multilanguage
• Variations– Is really a copying mechanism
• Resources files– Resource folders– Resx files
• Custom code must support Multilanguage– Web Part output– Editor Parts– Custom forms
Resource files• Application resources
– Used within the normal execution of the SharePoint application. Think of Application Pages, Web Parts and Controls
– For multilangual lists: 12\CONFIG\Resources\ – For local webapplications: <Website URL>\App_GlobalResources\
• Caveat: cannot deploy by WSP package
• Provisioning resources– are used when provisioning elements. Think of features, site definitions and list definitions
– 12\TEMPLATE\FEATURES\<feature>\Resources\Resources.<culture>.resx – 12\TEMPLATE\FEATURES\<feature>\Resources\ – 12\Resources\
• Administrative application resources– Used within the normal execution of the SharePoint application. Think of Application Pages,
Web Parts and Controls inside the administrative environment
– 12\CONFIG\AdminResources\ – <Website URL>\<port>\App_GlobalResources\
Resource files usage
• C#– HttpContext.GetGlobalResourceObject("MyResource",
"MyName").ToString();
• ASPX properties– <%$Resources:MyResource, MyName%>
• XML– $Resources:MyResource, MyName
• XML features, using the default resource file– $Resources:MyName
Demo
Using a resources for
custom multi language Web Part
Solution deployment
• Deploy the Solution package to the farm • Retract the Solutions package • When a new web server is added, automatically
deploy the solution to it • Deploy new versions of the Solution• Solution - A CAB file containing
– Manifest.xml file – All the files for the Features, Web Parts, Site or list
def changes, etc... that make up your solution
Solution deployment
• “Featurize” your custom development– Any SharePoint element– Changes in your web.config– Copying files to specific web folders
• Deploy features and other assets by WSP Solution package
Development and testing
• Your development machine does not go into production
• Use a buildserver
• Always test with different set of browsers (level 1 and level 2)
• Watch out for rights
CodePlex
• The starting point of a lot of new SharePoint functionality
• Community Kit For SharePointhttp://www.codeplex.com/CKS
• SharePoint learning kithttp://www.codeplex.com/SLK
• SharePoint Featureshttp://www.codeplex.com/features
• Podcasting kit for SharePointhttp://www.codeplex.com/pks
• Smartpart for SharePointhttp://www.codeplex.com/smartpart
• SharePoint AJAX toolkithttp://www.codeplex.com/sharepointajax
Resources
• Best practices resource center for SharePoint 2007 http://technet.microsoft.com/en-us/office/sharepointserver/bb736746.aspx
• Patterns and practices SharePoint guidancehttp://www.codeplex.com/spg
• Best practices for SharePoint guidance http://msdn.microsoft.com/en-us/library/dd203468.aspx
• SharePoint Deployment Planning Serviceshttps://iwsolve.partners.extranet.microsoft.com/SDPS/
• Downloadable book: Design and build sites for Office SharePoint Server 2007http://go.microsoft.com/fwlink/?LinkId=110087
• Other resources such as http://www.codeplex.com / http://www.dutchsug.nl / www.microsoft.com/sharepoint
• Gary Lapointe STSADM http://stsadm.blogspot.com/
• Firebug https://addons.mozilla.org/nl/firefox/addon/1843
• Yslow https://addons.mozilla.org/nl/firefox/addon/5369
More resources
Questions?