Use eventhandler to create the start workflow bar in the list.

Source: Internet
Author: User

I. UseEventhandlerCreate the start workflow bar in the list. First, obtain the list of trigger events and combineURL, WhereTemplateidBy reading the related list of workflows (List. workflowassociations) To obtain the list of trigger events.ID, SetURLAssign a value to the list item to update the list item.

 Public Class Meeting:Spitemeventreceiver

{

Public StringStartwfstring =String. Empty;

Public Override VoidItemadded (SpitemeventpropertiesProperties)//Heavy LoadItemaddedFunction to monitor new List entry events

{

Spsecurity. Runwithelevatedprivileges (Delegate()//Use this method to simulate the Administrator account to run this event.Program

{

Using(SpsiteSite =New Spsite(Properties. siteid ))//This method is not required.Dispose ()Now

{

Using(SpwebWeb = site. openweb (properties. openweb (). Id ))//Note thatWebMethod !!!

{

Try

{

Startwfstring = web. url;

If(! Startwfstring. endswith ("/"))

Startwfstring = startwfstring +"/";

Startwfstring + ="_ Layouts/iniwrkflip. aspx? List =";

SplistList = web. Lists [properties. listid];//Obtain the list of trigger events

SpworkflowassociationcollectionWfcollection = List. workflowassociations;

//Start workflow Column

System. xml.XmldocumentDoc =NewSystem. xml.Xmldocument();

Doc. loadxml (wfcollection. soapxml );

System. xml.XmlnodeNode = Doc. selectsinglenode ("Workflowtemplates/workflowtemplate/workflowtemplateidset/@ templateid");

If(List. enableminorversions)

{

List. enableminorversions =False;

}

Startwfstring + = List. ID +"& Id =";

SplistitemItem = List. Items. getitembyid (properties. listitemid );//Get the list of trigger events

Startwfstring + = properties. listitemid +"& Templateid =";

Startwfstring + = node. innertext +"& Source =";

StringPurl = web. parentweb. url;

StringListurl = List. defaultviewurl;

Startwfstring + = purl + listurl;

Item ["Startworkflow"] = Startwfstring;

Item ["Title"] = Item. file. Name;

Item. Update ();

StringTMP = item ["Startworkflow"]. Tostring ();

If(TMP. Contains (","))

{

String[] Arr = TMP. Split (New Char[] {','});

Item ["Startworkflow"] = Arr [0] +",Start Workflow";

Item. Update ();

}

List. enableminorversions =True;

}

Catch(ExceptionEx)

{

Properties. errormessage = ex. message;

}

}

}

});

}

}

II, DeploymentEventhandler

ExploitationD: "moss" eventhandlerexplorer "eventhandlerexplorerFor project deployment, clickEventhandlerpolicer.exe.

U2ucamlcreator.exeYou can query the basic information of the list.

Spcamleditor.exeModify the basic information of the list.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.