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 am a newbie in the custom workflow development. The scenario I want to send an email notification to the group when an item is created in the list. I am referring to http://davesquared.net/2007/07/sending-email-to-group-with-sharepoint.html Depending on the above explanation I wrote the below code, however the _Context object is always null "var _NameToEmailResolver = new NameToEmailResolver(_Context);"

Any thoughts on why _Context is null, and how to get the workflow context. below is the code which i implemented. is it required to have more than 1 dependency property to achieve below functionality. Will appreciate if any one helps with this.

public sealed partial class Workflow1 : SequentialWorkflowActivity
{
    public Workflow1()
    {
        InitializeComponent();
    }

    public Guid workflowId = default(System.Guid);
    public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
    public static DependencyProperty _ContextProperty = DependencyProperty.Register("_Context", typeof(WorkflowContext), typeof(Workflow1));
    public WorkflowContext _Context
    {
        get
        {
            return (WorkflowContext)base.GetValue(_ContextProperty);
        }
        set
        {
            base.SetValue(_ContextProperty, value);
        }
    }

    private void createEmailMessage_ExecuteCode(object sender, EventArgs e)
    {

        var _NameToEmailResolver = new NameToEmailResolver(_Context);

        string _Group = workflowProperties.Item["Assignee"].ToString();
       _Group=_Group.Split(new char[] { ';' })[1].Remove(0,1);
        this.sendAutomatedEmail.To = _NameToEmailResolver.GetEmailAddressesFromName(_Group);
        this.sendAutomatedEmail.From = "donotreplay.com";
        this.sendAutomatedEmail.Body = "Title :" + workflowProperties.Item["Title"];
    }
} 
share|improve this question

2 Answers 2

You may need to pass in the context parameter in the .ACTIONS file, add the following to the <parameters> section:

<Parameter Direction="In" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Name="__Context" />

See http://davesquared.net/2007/07/sharepoint-aware-workflow-activities.html for details.

share|improve this answer

You might need the ApplyActivation activity in the designer in Visual Studio.

Set the __Context to your WorkflowContext _Context property and the __WorkflowProperties to workflowProperties field.

This initialises the context. http://msdn.microsoft.com/en-gb/library/microsoft.sharepoint.workflowactions.applyactivation.aspx

http://social.technet.microsoft.com/forums/en-US/sharepointdevelopmentprevious/thread/e7236d96-133a-42fa-8227-dabb4a70d767

share|improve this answer

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.