Top Banner
AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem ([email protected] ) MVP SharePoint Portal Server 2003 U2U ALS310
29

AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem ([email protected])[email protected] MVP SharePoint Portal.

Dec 24, 2015

Download

Documents

Gordon Barrett
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: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Building WorkFlow Solutions with Windows SharePoint Services

Patrick Tisseghem ([email protected])MVP SharePoint Portal Server 2003U2U

ALS310

Page 2: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Me.About()

Managing Partner U2U .NET Development Training and Services MVP SharePoint Portal Server

My work? SharePoint Development Workshops Community Work

SmartPart CAML Query Builder SharePoint Application Blocks Blog – http://blog.u2u.info/patrick

EMEA Ascend Trainings Office smart client Trainings Portal Boot camps and Workshops

Page 3: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Agenda

Workflow out of the box – Is it enough? Creating a custom workflow solution SharePoint Workflow Application Block (SWAB) Summary

Page 4: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Workflow out of the box

Covers only the basic content approval steps

How it works Turn on content approval at the level of the

document library or form library Appoint users the role of approvers Submissions will not be visible until approver

comes in and approves or rejects

Limitations No parallel or serial approval routes No actions available

Page 5: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

What do we miss?

Serial or parallel approval routes Dynamic list of approvers Notifying approvers via emails Richer support for supplying comments when

approving or rejecting Tracking and logging of the workflow steps

Page 6: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Creating a Custom WorkFlow Solution

Quick overview of classes within the WSS object model we will use

Preparing the SharePoint-enabled virtual server Creating a document library event handler

.NET class library implementing the IListEventSink interface

Adding our code Signing the assembly and deployment in the GAC Attaching the assembly to the document library Testing and debugging

Page 7: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Sample we will work out

Speakers

SpeakerDocument Library

1

2

PublicDocument Library

ReviewersDocument Library

6

.NET Assembly3

Reviewers

List

4

Reviewers

7

5

.NET Assembly

8

11

10

12

Everyone

13

9

Page 8: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Object Model Refresher

SPSite SPWeb SPList SPDocumentLibrary

SPListItem SPFolder SPFileCollection SPFile

Page 9: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Time to get into the code…

Page 10: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Preparing our Virtual Server

SharePoint Central Administration Configure Virtual Server Settings Select your Virtual Server Virtual Server General Settings Turn on Event Handlers

Page 11: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Creating the Event Handler

Normal .NET Class Library C# or VB.NET Take care of your namespace

Set Reference to Microsoft.SharePoint.dll

Page 12: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Implement IListEventSink

OnEvent member to implement SharePoint provides you context information

through the SPListEvent type argument Common properties we will use

Type, Site, PropertiesAfter, URLAfter

using System;using Microsoft.SharePoint;

namespace Advisor.WorkFlow.Demo{ public class SpeakerDocHandler: IListEventSink { public void OnEvent(SPListEvent listEvent) { } }}

Page 13: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Checking Type of Event and Item Metadata

SPListEventType Checkin, Checkout, Copy, Delete, Insert, Invalid,

Move, Update, UnCheckout Note: your code gets notified after the event has

fired Use PropertiesAfter to check value of column

if((listEvent.Type==SPListEventType.Update) && (listEvent.PropertiesAfter["Status"].ToString()=="Ready For Review")){}

Page 14: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Lookup Reviewer

Two possibilities here Object model drill-down CAML query

SPWeb web = listEvent.Site.OpenWeb("/advisor");SPList list = web.Lists["Reviewers"];SPUser reviewer = null;foreach(SPListItem item in list.Items){ if(item.ID==Convert.ToInt32(listEvent.PropertiesAfter["Track"])) {

string[] reviewerTmp = item["Reviewer"].ToString().Split(';');int reviewerID = int.Parse(reviewerTmp[0]);reviewer = web.Users.GetByID(reviewerID);

}}

Page 15: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Lookup Reviewer

CAML Query SPQuery class

U2U CAML Query Builder Utility Build your query in a WYSIWYG way Helper class to execute query

U2U.SharePoint.CAML.Server.Helper caml = new U2U.SharePoint.CAML.Server.Helper(camlFile,track)DataTable tbl = caml.ExecuteQuery();

Page 16: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

CAML Query Builder Utility

Free tool available from http://www.u2u.info/sharepoint

Page 17: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Sending the Email

Reviewers can subscribe to alerts Programmatically sending the email

System.Web.dll System.Web.Mail namespace

if(reviewer!=null) { SmtpMail.SmtpServer = SMTPServer; SmtpMail.Send(fromEmail, reviewer.Email,"Presentation to review",

"A new presentation is ready for your review"); }

Page 18: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Copying Document and Updating MetaData

Using UrlAfter property of SPListEvent to quickly grab the SPFile object

Ways of copying or moving SPFile.CopyTo method

SPFile.MoveTo method

web.Lists.IncludeRootFolder=true;SPList reviewerLib = web.Lists["Reviewer Library"];SPFile doc = web.GetFile(listEvent.UrlAfter);doc.CopyTo(reviewerLib.RootFolder.Url + "/" + doc.Name,true);

web.Lists.IncludeRootFolder=true;SPList reviewerLib = web.Lists["Reviewer Library"];SPFile doc = web.GetFile(listEvent.UrlAfter);

Page 19: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Copying Document and Updating MetaData

Problem: Part of the auditing information is overwritten

with CopyTo and MoveTo Reason:

Your code is executed with the account of the worker process!

Solution: Read the file content and add a new SPFile object

manually to the SPFileCollection of the destination folder

SPFolder fld = reviewerLib.RootFolder;SPFileCollection files = fld.Files;files.Add(fld.Url + "/" + doc.Name, doc.OpenBinary(), doc.Author, doc.ModifiedBy, doc.TimeLastModified, doc.TimeCreated);

Page 20: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Copying Document and Updating MetaData

Use the Item collection Don’t forget the Update() method call

doc.Item["Status"] = "Currently in Review";doc.Item.Update();

Page 21: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Deploying the Event Handler

Strong name the assembly Create a public/private keypair using sn.exe Point to snk file within assemblyinfo file in project

Deploy the assembly in the GAC Drag and drop Gacutil.exe /i

Notes Use fixed version number IISReset is required to test latest copy C# can use postbuildevent in VS.NET

Page 22: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Activating the Event Handler

Advanced settings of document library Avoid typing mistakes

Use .NET Reflector (www.aisto.com)

Full Strong Name

Full Class Name

Page 23: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Exceptions and Debugging

SharePoint user is not confronted with unhandled exceptions

Developers need to consult application log in event viewer to get description of exception

Use VS.NET to attach to ASP.NET worker process that runs your code and set breakpoints

Page 24: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Things to be aware of

Event-handlers can only be attached to document and form libraries, not to lists

Code runs asynchronously in new thread Events are notified after the action has occurred Code is executed with account of the application

pool Impersonation within code (P/Invoke) Execute your code in COM+ application Execute your code in a Web Service

Page 25: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

WorkFlow Lite

Available for free on GotDotNet Doing the same things we have done but in a

more configurable, generic manner

Page 26: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Workflow Application Block

SharePoint SiteSharePoint Site

SharePoint Doc.Lib.SharePoint Doc.Lib.

SharePoint Doc.Lib.SharePoint Doc.Lib.

Workflow EngineWorkflow Engine

XMLXMLDocument Library Event HandlerDocument Library Event Handler

Page 27: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Summary

Library Event Handlers are a great way to extend the functionality of a SharePoint document library or form library

Not only workflow, also e.g. version pruning, providing undelete functionality, …

Learn the object model before you start Think about re-usability (e.g. WorkFlow Lite

approach) Many third-party solutions are available

K2 WorkFlow Captaris Teamplate Skelta WorkFlow Nintex SmartLibrary

Page 28: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

ADVISOR LIVE Web Update Page

AdvisorEvents.com/cmt0506p.nsf/w/cmt0506ud

This session WILL NOThave updates.

Page 29: AdvisorEvents.com Building WorkFlow Solutions with Windows SharePoint Services Patrick Tisseghem (patrick@u2u.net)patrick@u2u.net MVP SharePoint Portal.

AdvisorEvents.com

Thank you!

Please remember to fill out your evaluation.