0

I would like to add workflow to my webpart. Whenever items added or removed from webparts my workflow needs to be started. I am not sure what my web part will have - it can have any items like list, asp.net controls, etc. Is this possible?

4
  • 2
    Your question doesn't make sense - web parts don't 'have' lists and asp.net controls don't have workflow. Are you talking about putting a workflow on a list?
    – Ryan
    Mar 1, 2012 at 8:19
  • My scenario is whenever particular user edits or create any item inside web part i need to call a workflow and that workflow should decide whether particular user has permission to create or edit..am i clear..
    – Sanker
    Mar 1, 2012 at 8:42
  • Clear? Not really. Is the web part a custom web part or the built in ones? What is it creating - is it items in a SharePoint list or something else?
    – Ryan
    Mar 1, 2012 at 8:44
  • Custom web part with any type of content..
    – Sanker
    Mar 1, 2012 at 8:47

1 Answer 1

2

if it is a webpart you have built you can manualy start and stop the workflow

here is a snippet

   public void StartWorkflow(SPWorkflowManager manager,string eventData,SPListItem listItem,SPWorkflowAssociation workflow)
   {
       SPWorkflowCollection workflows = manager.GetItemActiveWorkflows(listItem);
       if (workflows.Count > 0)
       {
           return;
       }
       manager.StartWorkflow(listItem, workflow, string.Empty, true);
   }

WorkFlow Manager Refrence http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowmanager_members.aspx

EDIT:

You will have to create the method that fires the workflow i usualy use an eventreciver of some sort. but as your question is very general i cannot give you a solution for that. but if for example you are displaying a list via a webpart. attatch an event reciver to the list and it will be kicked of if you edit it in the workflow

5
  • my web part can have any type of content..also if my web part has more than one content then i have to write event receiver for each content..
    – Sanker
    Mar 1, 2012 at 8:55
  • 1
    the issue is that your question is very general. but for every type of webpart you would have to code a different even reciver Mar 1, 2012 at 9:07
  • ok then i have to use event receiver for every content that i use in my web part and from there i have to start my workflow..
    – Sanker
    Mar 1, 2012 at 9:10
  • no, its not realy about the type of content its more about. how the content gets manipulated is it a list is their a form with a submit button etc. because depending on that you will either attach a event reciver or create a custom function. because if you look at the event reciver specs it can only attach to certin events Mar 1, 2012 at 9:45
  • You shouldn't pass an empty string for the eventData parameter. You should pass an empty XML tag instead, like <root />.
    – Geeky Guy
    May 28, 2013 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.