1: using System;
2: using System.Runtime.InteropServices;
3:
4: using Microsoft.SharePoint;
5: using Microsoft.SharePoint.WebControls;
6: using Microsoft.SharePoint.Workflow;
7:
8: using System.Web;
9: using System.Web.UI;
10: using System.Web.UI.WebControls;
11: using System.Web.UI.HtmlControls;
12:
13: namespace CustomButtonField
14: { 15: // TODO: Replace, as needed, "TextField" with some other class derived from Microsoft.SharePoint.WebControls.BaseFieldControl.
16: [CLSCompliant(false)]
17: [Guid("9fbee449-9f7f-48de-999b-d7187dfe78cf")] 18: public class ButtonFieldWFFieldControl : TextField
19: { 20:
21: private Button oBtnWF = null;
22:
23: protected override void CreateChildControls()
24: { 25: base.CreateChildControls();
26:
27:
28: if (this.ControlMode == SPControlMode.Edit || this.ControlMode == SPControlMode.New || this.ControlMode == SPControlMode.Display)
29: { 30: oBtnWF = new Button();
31: oBtnWF.Text = "Start the custom WF";
32: oBtnWF.Click += new EventHandler(oBtnWF_Click);
33: base.Controls.Add(oBtnWF);
34:
35: }
36: }
37:
38: void oBtnWF_Click(object sender, EventArgs e)
39: { 40:
41: SPSite oSite = this.ListItem.Web.Site;
42:
43: //get the workflow associated with this doc lib and kick if off
44: if (this.List.WorkflowAssociations.Count > 0)
45: { 46: // kick off the first workflow..you can kick off your custom workflow by taking it properly
47: SPWorkflowAssociation wrkFl = this.List.WorkflowAssociations[0];
48: oSite.WorkflowManager.StartWorkflow(this.ListItem, wrkFl, wrkFl.AssociationData, true);
49: }
50: System.Web.HttpContext.Current.Response.Write("started..."); 51:
52: }
53:
54: protected override void Render(HtmlTextWriter output)
55: { 56: this.oBtnWF.RenderControl(output);
57: }
58: }
59: }