Categories

Bootcamp SharePoint 2007 Advanced

Agenda
- WSS solution plattform
- Site provising engine
- Features
- Site pages
- Application pages
- Provisioning content storage structure
- Information management policies
- OM/WS to access lists
- Security
- Branding
- Publishing Pages
- WebParts
- BDC
- Search API
- Workflows
- Upgrading and versioning
- InfoPath Form Services

Day 1
Deeper Look into WSS solution plattform
- Request processing in IIS: http.sys -> aspnet_isapi extension -> worker process w3wp.exe (one per application pool, IIS 6.0 and higher)
- Worker process has: HttpContext, HttpApplication, HttpModule and HttpHandler
- SharePoint: SPHttpApplication, SPRequestModule, SPHttpHandler
- IIS web site corresponds to SP web application
- SharePoint stuff is tied up in web.config on web application creation
- Tip for dev machine: Use as few application pools as possible to save resources
- Multi-language support: www.icefire.ca (HttpModule)
- Do not change any of the out-of-the-box resources (everything in 12 hive) – otherwise no support from MS
- Redirect HttpModule: BeginRequest check on URL and redirect, hook up in web.config
- SPFarm: Local (current), Joined (when current farm is connected to other farms)
- SPServiceInstance: timer service, search servie
- Extend STSADM: Implement ISPStsadmCommand, deploy to GAC, register with stscommands.uniqueID.xml in \12\config, see stsadm.blogspot.com and andrewconnel.com
- Use SPWebConfigModifications and SPWebApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications()

Creating sites programmatically
- SiteCollection: Security boundary, provisioning components (webparts, fields, contenttypes,… )
- When creating more than one site collection, other site collections are created under a manage path (Application Management / Defined Managed Paths: Have implicit/wildcard inclusion
- Create new content databases manually (Application Manangement / Content Databases), new site collection created will always be memember of the content database with the lowest site collection count (unless you set the maximum site collection count)
- See u2u-createsite stsadm extension to create a site collection on specified content database (uses a private method of the OM via reflection)
- SPServer – corresponds to a web server
- Virtual file system supports web dav (file share on a SP list)
- Custom ASMX web services: copy to \12\ISAPI, run disco.exe, … (see page 39)

Extending the Site Provisioning Architecture
- Site Template: On site creation a copy of the template is used (later changes cannot be pushed down to sites using the template), saved as STP file in content database in site template gallery, can be saved with content, max size 50 MB (max file size)
- Site Definition: \12\template\SiteTemplates, STS – SharePoint Team Services (Team Site), Global site definition provision basic infrastructure (galleries, default.master, …)
- WEBTEMP.XML: Language specific file used to activate site definition (web template) / what is shown on create site page (in \12\template\1033\xml)
- ONET.XML: Configuration for the site definition / what is executed on site creation
- Page template files: Used to provision home page and secondary pages
- Only Moss 2007: Sub site setting on site settings to configure what site definitions are allowed, or build custom provisioning page
- Name property in webtemp.xml points to sub folder in 12\template\sitetemplates and ID must be greater than 10000 (unique within farm)
- ONET.XML section:
  – NavBars
  – Configuration – at least one per site definition: Lists, features
  – Modules – site pages with web part configuration
- ONET.XML: Can contain multiple site definition with multiple configurations, configuration IDs need to be unique within each site definition
- Recommendation: Stay away from site definitions as long as possible, rather use features, lot of files involved, can only be applied to new sites
- Tool: SharePoint Solution Generator (VSexWSS) to generate XML files
- Changes in XML files require app pool recycle
- STS#1 means configuration 1 in STS site defnition
- SPWebProvisioningProvider: Is executed early in the site creation stage, add ApplyWebTemplate(”") to provision a site, add your custom code afterwards, is specified in webtemp.xml, create configuration without ProvisioningProvider to avoid endless loop
- Publishing.PortalProvisioningProvider uses same mechanismn to create a hierarchy of sites based on a XML file

Features
- Are installed at farm level and activated at activation scope
- Required: feature definition file
- Opitonal: feature element definition file, feature helper files (resources, page templates, …)
- Create reference to \12\template\xml\wss.xsd or add a reference to catalog.xml to wss.xsdcaml.net intellisense
- URL tokens: To reference list or sites dynamically, {SiteUrl}, {ListId}, {ItemId}, {ItemUrl}
- Localization of features: $Resources:FeatureTitle; with resource file (resx) located in Resources sub folder of feature folder (local resource) or $Resources:U2UFeatrues,Key1; in \12\resources (shared resources), the displayed language depends on the installed language pack and in what language the site was created

Day 2
Features continued
- Nested custom actions, generate a fly-out menu: Cannot be built directly in mark-up, specify ControlAssembly and ControlClass in custom action, ASP.NET server control with SubMenuTemplate and MenuItemTemplate (see chapter 4, exercise 5)
- Activation dependency: You can only have dependencies to a feature that at the same or higher scope, the feature with the activation dependency can only be activated if the dependent feature is activated or automatically (if dependent feature is hidden and at same scope)
- Deactivation: When the feature with the activation dependency, that activated the dependent feature, is deactivated the dependent feature is activated to (should have a counter so that it is only deactivated when no other feature with the dependency are activated)
- Feature stapling can add features to a site definition, e.g. extend all team sites with another feature, FeatureSiteTemplateAssociation, must be at Farm scope, does only apply to newly created sites – does not affected existing sites
- Farm features are always activated automatically
- Versioning: Does not do anything – for future purpose only

Site pages
- Uncustomized/customized (ghosted is 2003 terminology), SharePoint Designer and UI can customize pages and other artifacts
- SPFile.ReconvertContentStream to uncustomize a customized file or Reset to site definition from Site Settings menu
- Feature can also provision site pages (like a site definition) with module element within feature elements definition
- Use default.master as master page (will be dynamically replaced with the master page currently in use)
- Type: Ghostable/GhostableInDocumentLibrary
- Provisioned files are not removed on deactivation
- Placeholders: PlaceHolderMain, PlaceHolderPageTitle, … Check master page for more
- No-inline code allowed, will throw exception when opening the page, so put code in controls

Web Part Pages
- To support web parts: Inherit WebPartPage and add at least one web part zone
- Feature receivers
- SPLimitedWebPartManager is on the master page, PersonalizationScope: private (user settings) or shared (general settings)

Application pages
- Base class: LayoutsPageBase or UnsecuredLayoutsPageBase, uses application.master as master page
- Is the same for all sites in the farm
- Bread-crumb is not shown, add to _app_bin\layouts.sitemap file, same story for the central administration, deployment: put layouts.sitmap.xxxx.xml file in \12\template\layouts (works for new sites or run stsadm -o copyappbincontent)
- Only logged-in users have access to application pages that inherit from LayoutsPageBase
- UnsecuredLayoutsPageBase for login pages
- Useful SharePoint controls: user controls in \12\controltemplates (ToolBar.ascx, ToolBarButton.ascx, InputFormSection.ascx, InputFormControl.ascx), SPDataSource, SPHierarchyDataSource, SPTreeView, WebApplicationSelector

Content Storage Infrastructure
- List templates and list definitions (same story as site template/definition)
- List BaseType is defined in onet.xml of global site definition: 0 to 5
- List template name referes to sub folder with schema.xml
- ListType must be unique and greater than 10000
- You can use the SharePoint Solution Generator to generate a list definition
- Site columns
- Content types: can have event handlers
- List has setting in UI to enable content type management
- Meta data is display and can be edited in word documents, you can add quick parts to embed the data in the word document (cool!)
- Creating a site column in UI: Entered name will be display name and static name, when changed afterwards only the display name is changes – so use clean names without special characters and spaces when you want to use the site column from code
- Feature approach advantage: Custom forms, block inherited fields, register event handlers, reusable
- LCID – Language Identifier, e.g. used with currency field to determine the currency (Denmark 1030)
- Site columns and content types can be in the same elements file, it is only a question of deployment structuring where to place them
- List instance: Placed in the feature elements definition
- List forms: Rendering template and page to display can be defined (it is not clear how this exactly works)
- Custom field limitations: No office 2007 support, no datasheet view support, can only be deploy to whole farm
- SPFieldMultiColumn to store multiple values in one column
- PropertySchema in Custom Field definition to specify values when add field to list

Day 3
Working with lists
- SPQuery: SPListItemCollection cannot bind directly to datagrid, use GetDataTable method
- SPSiteDataQuery: Query across different sites, get results from more than one list
- Event handlers: -ing events are sync and executed before, -ed events are async and executed after, no information about thread-safety of async
- Receiver mark-up contains Data element that can pass a string to the event handlers ReceiverData property
- Disable/EnableEventFiring when updating an item in Updating event
- Copy/Paste to clipboard and other doc lib function (smarttools.copypaste)
- SPLongOperation – Shows the waiting animation while code is executed
- SPFile.CopyTo can only be used within the same site
- Auditing at site collection level, no UI support in WSS but Moss
- WSS: SPList.Audit.AuditFlags and SPList.Audit.Update() to activate on a list and SPSite.Audit.GetEntries with SPAuditQuery, result must manually be transformed to a DataTable
- SPList.Audit.WriteAuditEvent
- Using the list web service, create service reference on /_vti_bin/lists.asmx, load result into XML
- Document workspace web service
- FrontPage RPC is best way to up/download documents to SharePoint, check SharePoint SDK and Fiddler to analyze office application or wrapper on codeplex

Security
- User administration:
  – people and groups (SPPrincipal: SPUser, SPGroup)
  – permissions (SPBasePermission) and permission levels (SPRoleDefinition)
  – role assignments (SPRoleAssignement), securable object (ISecurableObject: SPList, SPWeb, SPSite, SPFolder, SPListItem)
- SPWeb.Users: all users with explicitly assigned permissions, SPWeb.AllUsers: all members or users who have browsed the site
- SPWeb.EnsureUser to create user from AD Group that not yet has visted the site
- User details are automatically populated from AD for AD users, only create them with login
- One SharePoint URL can support one authentication types, therefore use extended sites, zone specifies what authentication is being used, add connection string LocalSqlServer to web.config, specify AspNetSqlMembershipProvider, create user database with aspnet_regsql.exe, use e.g. Web app admin site in any VS web site project to add users
- Only a forms account can give permissions to a forms account, add user via CA/policy for web application after adding LocalSqlServer to CA web.config
- Provider: ActiveDirectoryMembershipProvider, SqlMembershipProvider, CustomMembershipProvider, check codeplex for xml providers and the like
- Impersonation:
  – Pass user token when creating SPSite (get user token from SPUser.UserToken), meta data of impersonated user
  – SPSecurity.RunWithElevatedPrivileges (runs with app pool account), meta data of current user

Branding
- Master pages stored in site collection master page gallery (WSS only master pages, Moss has master pages and page layouts)
- Set as Default Master Page / Set as Custom Master Page settings in SharePoint Designer
- Moss has UI to change current master page
- Master pages can be provisioned via a module with url=”_catalogs/masterpage” and list=”116″
- Use a Web scoped feature to activate the custom master page for a specific web via FeatureActivated event
- Styling of OOTB application pages: Codeplex Superbranding – uses a HttpModule
- Master page provisioning on Moss sites requires ContentType property
- Delegate control in master page can be replaced with control through feature activation, sequence number decides what to show (lower number has precedence)
- AdditionalPageHead delegate control, has multiple controls enabled, placed in <Head> section of the master page
- Apply custom css: WSS – SPWeb.AlternateCssUrl, Moss – UI functionality, custom master pageg with CssRegistration control or css link
- Navigation: uses ASP.NET navigation provider model – Control -> SiteMapDataSource -> SiteMapProvider -> gets data from content database
  – Navigation control is AspMenu control: DataSourceID, Orientation, StaticDisplayLevels, MaximumDynamicDisplayLevels
  – PortalSiteMapDataSource is used
  – PortalSiteMapProvider is registered in web.config
    – Global navigation: as used in top link bar
    – Current: as used in quick launch, navigation for current site
    – Combined: as global when site does not inherit global navigation

Publishing Pages
- Moss only
- Pages created in document library are based on page layout (from masterpage gallery) as in Collaboration Portal and Publishing Site via the CreatePage.aspx
- Page layouts are always based on content type
- Provisioning a page layout: ContentType (value displayed to user), PublishingAssociatedContentType (CT Guids)
- Publishing OM: PublishingSite, PublishingWeb, PageLayout, PublishingPage
- Page editing toolbar can be customized (page toolbar when editing a page): PublishingConsole.ascx, EditingMenu.xml and QuickAccess.xml – customize via master page gallery

Day 4
Web Parts
- Common mistakes: Web part class not public, typo in SafeControls (case-sensitive), DLL copied to the wrong bin folder
- Feature deploy of web parts, feature must have Site scope, module with target List=”113″ and Url=”_catalogs/wp”
- Connectable web parts, provider/consumer, used for master/detail views (e.g. list view web part)
  – Provider implements data contract
  – Provider has method decorated with ConnectionProvider attribute
  – Provider has no event handler for the event handler, only used to post-back the page
  – Consumer has method decorated with ConnectionConsumer attribute
  – Consumer should have null check for provider – so code does not fail when not connected
- User properties: WebBrowsable attribute and Personalizable attribute
- Custom EditorPart to configure web parts: Inherit EditorPart, base.WebPartToEdit to access web part under edit to set value, must get an unique ID assigned in constructor, ApplyChanges returns a boolen – when returning false the settings cannot be applied, add Editor Part to EditorPartCollection in web part, remove WebBrowsable attribute from property, editor web parts are always displayed at the top
- Web part verbs to populate the web part edit menu, inherit WebPartVerb class, use base.Verbs
- Changing from bin to GAC deployment: SafeControl entry, webpart file in webpart gallery must be updated and all web parts must be re-added to pages (a copy of the web part configuration is saved to the page)

Code Access Security
- Set trust level in web.config: WSS_Minimal, WSS_Medium, WSS_High, Full
- Deploy to GAC
- Tip: Always sign assemblies so you do not have to change references later
- Create custom trust file, add  code group,  use “secutil -hex -s” to determine publickeyblob for assembly (not the same as publickeytoken)
- Use a solution package (WSP) to update the trust file

Pimp your SharePoint
- Think about the level of customization: Web Browser to Feature deployed code
- Update Panel, contents is in ContentTemplateContainer.Control
- ScriptManager: a. put in master page or b. add script manager dynamically (ScriptManager.GetCurrent(Page)
- JavaScript fixups: UpdatePanel is not compatible with SharePoint javascript, check Mike Ammerlaan blog
- Add ajax settings to web.config, lazy way: create new web site, copy SharePoint web.config, change web site to .NET 3.5, copy modified web.config back to SharePoint
- Connected web parts using update panels
- AJAX Control Toolkit: Requires valid HTML in page output, e.g. pop-up extender fails in SharePoint
- ScriptManagerProxy for usage in ASCX user controls to ensure that e.g. a service reference is in the pages ScriptManager
- jQuery: Javascript library (integrated in .NET 4.0), extensible, function: Select DOM elements, manipulate DOM, call web services, see jquery.com
- jQuery web service calls will run with the currently logged on user
- See jQuery loader from smarttools to upload jQuery to a document library (available soon)
- Task list demo (jQuery only)
- Filtered lookup demo
- jQuery will be embedded in Moss 2010
- Hosting silverlight content: inside <object /> tag (assumes that client has Silverlight installed), server control or silverlight.js
- Building a SilverLight web part: System.Web, System.Web.Extensions, System.Web.SilverLight references, Silverlight control, set width/height and source for XAP file, requires ScriptManager on page
- For Windows 2003 Server you have to add a .xap mime-type mapping in IIS admin
- Silverlight control to play videos from doc lib
- Use InitParameters property to pass parameters to Silverlight application
- jQuery hosting of Silverlight application, requires only uploads
- Tip: Use net stop sens when no LAN connection on local machine working with SharePoint

Search API
- Index engine maintains the index (SSP DB)
- IFilter to search within documents, such as PDF IFilter, …, you can create custom IFilters
- Content source to specify where to searc (SharePoint site, File share, …)
- OM: Create ServerContext and based on that the SearchContext
- Search Scope: automatically updated every 15 minutes, can be triggered manually, can e.g. include specific content sources
- Metadata property: site columns in content
- Managed property: search property that is mapped to a metadata property
- Showing the managed properties in advanced search is done by customizing the xml of the advanced search web part
- Check Search Usage Reports from Search CA to analyze users search patterns
- RecordClick web method to register what search results the users clicked on
- Search logging can be disabled
- Search reports cannot be customized, uses reporting services, but can be exported to Excel or PDF
- Customize search center: Search Center with tabs (Publishing) and Search Center Lite (e.g. Teamsite) (two site definitions)
- Two pages: search.aspx and results.aspx
- Results are rendered with a XSLT
- Changing the sort order: Create custom web part for search results with custom query
- Query syntax: keyword or sql
- Typ. you specify the scope you want to search in the where clause: select … from scope() where “scope” = …
- OM: Reference to Microsoft.Office.Server.dll and Microsoft.Office.Server.Search.dll, FullTextSqlQuery, default row limit is 50
- Web service: _vti_bin/search.asmx, Query – results in XML, QueryEx – results in Dataset
- SSP can be added to office search (cool!)
- Custom security trimmers: ISecurityTrimmer to filter out sensitive results, registration via STSADM
- Federation search to pass query to another search engine and show results in own site
- Federation can be configured by FLD files
- Faceted Search: Filtering of returned search results based on user input – built yourself, 3rd party tools or codeplex

Day 5
BDC
- Integrates external data with SharePoint, read-only access, entity level security
- Unsupported data sources can be wrapped into custom web service:
  – Keep output simple – arrays, int, string, …
  – IDs as string
  – Finder-type methods to enable search functionality
  – IdEnumerator type method
- Metadata model
  – LOBSystem (Line Of Business) – whole system, LOBSystemInstance – specific envirionment
  – Entity: Identifier, Methods, Actions (point to custom application page)
- Application definition file: models the system, bdc editor in SDK/BDC Meta Man (license 1200 USD) or reference bdcmetadata.xsd
- Import application definition file via Shared Services Provider UI
- Give search account access rights, if you want to index a BDC
- Action example: bing.com search
- Administrativ OM: Microsoft.Office.Server.ApplicationRegistry.MetaDataModel, SqlSessionProvider.Instance().SetShareResourceProvider, ApplicationRegistry
- BDC web parts: Business Data List, Business Data Item (connectable master/detail view), Business Data Field Type
- No BDC web services

Workflows
- InfoPath forms can be integrated in workflows
- Workflow consists of activities, build custom activities
- Custom activities: deploy to GAC, register authorizedType in web.config, .actions file for SharePoint Designer support (\12\template\workflow)s
- Activity properties: DepedencyProperty used for activities properties, properties are exposed to workflow users (like web part properties)
- Template (workflow definition), association (to content type of list), instance (created when workflow is started)
- Workflow logs to history list
- Building a basic custom workflow in VS: SharePoint workflow template
- Use this.workflowProperties.Item to access information from the underlying list item in e.g. if/else declarative condition
- Workflow extensions: Nintex, K2, … can save a lot of time in complex custom workflows
- Workflows are executed within w3wp.exe (number of simultaneous active workflows can be configured, usually 4), when number is exceed it will be executed by owstimer
- InfoPath forms as association form, deploy from feature (Property Key=”RegisterForm”) and WorkflowFeatureReceiver (OOTB in Moss)
- Complex workflow with InfoPath association form and custom aspx edit/display form, Submit button in InfoPath must submit data to “Hosting…”

SharePoint Solutions
- Manifest.xml: Features, CAS, Assemblies, Site definitions, …
- STSADM -o addsolution puts WSP into solution store (config DB)
- STSADM -o deploysolution deployes to WFEs
- SharePoint solution installer from codeplex: generates an installation wizard for WSP
- Tip: Use one key for all projects and one separate solution package to deploy only security policy (is linked to assembly blob)
- Upgrading a solution: Site columns, content types, site definitions cannot be upgraded (breaks lists using these)
- Check-out Echo tool: Synchronizes content type changes

People Management Features
- User profile database: Record for each user, can use BDC to read user data, configure via Shared Service Provider, extensible
- OM access: Microsoft.Office.Server.UserProfiles, UserProfileManager
- Audience: Grouping of users, managed in SSP, membership based on user or property rule, audiences must be compiled via ECB, can be used for content targeting, web parts or list items (must be enabled on the list), not filtered in search
- OM access: Microsoft.Office.Server.Audience, AudienceManager
- MySite infrastructure (personal site): Created on first visit, Organization hierarchy, In common with web part, Colleague Tracker web part, has its own site

Infopath
- External data: Receive and submit connections, primary and secondary data source, data connection library
- Direct interaction with SQL Server, other data sources via web services
- Web service interaction: DataSets also support
- Repeating structure in form, navigate to datasource to change default group names
- Default value: Function to grab data from datasource using a filter
- Deploy to SharePoint (can auto-create custom doc lib)
- Add save and close button with auto file name generation
- Relational data can only be projected to a multiple line text field, work-around: event-handler inspecting the form xml
- Allows multiple views in one form, so you can create a function to map the form schema to the underlying data
- InfoPath form is completly xml/xslt
- Data connection can be stored in data connection library to configure the data sources for forms
- Scripting object model or managed code OM: Microsoft.Office.Infopath
- Microsoft.Office.Interop.InfoPath to create forms from e.g. Win Forms application
- ActiveX control/Form control to display forms in Win Forms applications
- XmlFormView control for ASP.NET works only in SharePoint context, must have session state enabled, XsnLocation (form), XmlLocation (filled out form), submit action to hosting environment
- Visual Studio 2005 Tools for Applications (VSTA): Write .NET code in InfoPath directly – set default language to C#, Edit Form Code on e.g. a submit button
- Copy XPath function on datasource
- Deployment: Set compatiblity to Web site, Infopath cannot publish directly but generate an Administrator template, run upload form template in CA (app management), activate in site collection, add content type to doc lib where to use it, forms are version controlled (nice!), you can also use a feature or STSADM
- Pass custom parameters to form, loading event that reads input parameters and populates form with the data

Information Management Policy
- Scope: List, ContentTypes, Site collection (easy to reuse policy)
- Label policy: Will add a label, metadata to the actual document (Works only with 2007)
- Expiration policy with auto-delete or deletion approval workflow
- Barcode and auditing policy
- Custom policy: Implement IPolicyFeature or use User Control (ascx), reference Microsoft.Office.Policy, deploy to GAC, register policy definition file (custom code only)

Records Management
- Records Center site definition (Enterprise tab)
- Never created by default, should be stored in separate site collection/server (for legal reason), but technically possible
- Must be registered in CA/App Management/Configure Connection to Records Center pointing _vti_bin/officialfile.asmx
- Activates Send To ECB action in whole site collection
- Send To generates unique file name suffixes, per default everything is moved to unclassified documents
- Create document libs in Records Center, define Record Routing on ContentType basis
- Holding, entry in hold list, keeps document from being deleted by policy
- Only one Records Center can be specified OOTB, built your own web service to distribute records to more than one records center