Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
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 '12 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 '12 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 '12 at 8:44
    
Custom web part with any type of content.. –  Sanker Mar 1 '12 at 8:47
add comment

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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 '12 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 –  Sebastien Stettler Mar 1 '12 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 '12 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 –  Sebastien Stettler Mar 1 '12 at 9:45
    
ok ok i got it..Thanks a lot.. –  Sanker Mar 1 '12 at 9:56
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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