You are here: Code Zone » SharePoint
 Register    Login 
Free Code Minimize  
If this code is useful to you, please check out my sponsers for more great offers.

SharePoint Helper Code Library Minimize  
WorkFlowHelper.cs
WebServiceProxyHelper.cs
UserProfileHelper.cs
UpdatingContentTypeReceiver
TraceLogHelper.cs
SiteHelper.cs
SecurityHelper.cs
LibraryHelper.cs
FileHelper.cs
FeatureHelper.cs
1#region Credits
2
3// 	Tim Wheeler (www.purecoding.net)
4// 	Usage: Free to use
5
6#endregion
7
8#region Usings
9
10using System;
11using System.Diagnostics;
12using Microsoft.SharePoint;
13using Microsoft.SharePoint.Workflow;
14
15#endregion
16
17namespace SPHelper
18{
19    /// <summary>
20    /// Allows creation of Workflow History events
21    /// </summary>
22    public class WorkflowHelper
23    {
24        public static void CreateHistoryEvent(SPSite site, Guid workflowId, SPWorkflowHistoryEventType eventType,
25                                              string description, string outcome, string otherData)
26        {
27            CreateHistoryEvent(site, workflowId, eventType, -1, new TimeSpan(), description, outcome, otherData);
28        }
29
30        public static void CreateHistoryEvent(SPSite site, Guid workflowId, SPWorkflowHistoryEventType eventType,
31                                              int userId, TimeSpan duration, string description, string outcome,
32                                              string otherData)
33        {
34            try
35            {
36                using (site)
37                {
38                    using (SPWeb web = site.OpenWeb())
39                    {
40                        SPMember member = GetUser(userId, web);
41                        SPWorkflow.CreateHistoryEvent(web, workflowId,
42                                                      (int) eventType, member, duration,
43                                                      outcome, description, otherData);
44                    }
45                }
46            }
47            catch (Exception)
48            {
49                if (Debugger.IsAttached)
50                {
51                    Debugger.Break();
52                }
53            }
54        }
55
56        private static SPMember GetUser(int userId, SPWeb web)
57        {
58            try
59            {
60                return web.AllUsers.GetByID(userId);
61            }
62            catch (Exception)
63            {
64                return null;
65            }
66        }
67    }
68}

 Copyright 2008 PureCoding.net
 Terms Of Use     Privacy Statement