Windows Workflow Foundation 3


How to change the sendemail activity property at run time?


Hi, All,
I want to use the SendEmail sample activity for my workflow and looked through the EmailActivities Example. But how can I change the From, To, ect properties at run time?
My state machine workflow will send email to different perpole based on the selection from the dropdown list. I try to set these properties inside the activity at function sendEmail1_SendingEmail(object sender, EventArgs e), like,
this.sendEmail1.To = "AAA#abc.com";
but this way won't work, I get the error message " Property 'To' is not set." if I use ((EmailActivities.SendEmail)sender).To = "AAA#abc.com"; it will work.
What is the best way to change the dependency property for SendEmail activity at run time? Any suggestions?
 
Thanks for your help
 
Brian
Brian,
Your second technique is actually the correct way to do it.  In a StateMachineWorkflow, each state spawns a new execution context, which means that the actual running StateActivity (and the contained subtree within it) are clones of the actual tree and these are the activities that will actually execute.
If you do "this.sendEmail1", you are not getting a hold of the running instance of the SendEmail activity, you are actually calling the "template" activity.  When you use "sender", you are always ensured to get the correct (actual running) instance of the activity you are trying to modify.
-Angel
The easier way might be to just bind the to and from properties to some fields on your event arguments.  This would keep you from writing any code at all to set them, and guarantees that they get set on the right instance. 
Matt
Brian,
Your second technique is actually the correct way to do it.  In a StateMachineWorkflow, each state spawns a new execution context, which means that the actual running StateActivity (and the contained subtree within it) are clones of the actual tree and these are the activities that will actually execute.
If you do "this.sendEmail1", you are not getting a hold of the running instance of the SendEmail activity, you are actually calling the "template" activity.  When you use "sender", you are always ensured to get the correct (actual running) instance of the activity you are trying to modify.
-Angel
The easier way might be to just bind the to and from properties to some fields on your event arguments.  This would keep you from writing any code at all to set them, and guarantees that they get set on the right instance. 
Matt
Matt,
Thank you! Is there a sample or article to show how to bind some properties?
Brian
Hi Brian
 
I try to use ((EmailActivities.SendEmail)sender).To in sendEmail1_SendingEmail() but getting an type error. What is the correct syntax?
 
Marius
 
 
 
Imports SystemImports System.ComponentModelImports System.ComponentModel.DesignImports System.CollectionsImports System.DrawingImports System.Workflow.ComponentModel.CompilerImports System.Workflow.ComponentModel.SerializationImports System.Workflow.ComponentModelImports System.Workflow.ComponentModel.DesignImports System.Workflow.RuntimeImports System.Workflow.ActivitiesImports System.Workflow.Activities.Rules
 
Public Class SendEmailWorkflow    Inherits SequentialWorkflowActivity
    Private Sub sendEmail_SentEmail(ByVal sender As Object, ByVal e As EventArgs)
        Console.WriteLine("The email has been sent.")
    End Sub
 
    Private Sub sendEmail_SendingEmail(ByVal sender As Object, ByVal e As EventArgs)
 
        ((EmailActivities.SendEmail)sender).To  = "postmaster#example.com"
 
        Console.WriteLine("Preparing to send email.")
    End SubEnd Class
For me worked
 
((SendEmail)sender).To = "postmaster#example.com"
 
with namespace
 
Microsoft.SharePoint.WorkflowActions
 

Related Links

Developing an application for a service support provider.
WorkflowRuntime.CreateWorkflow Performance
Access sequential workflow dependency property from custom activity
Access to workflow queues from external processes
Persiste in a custom activity
Workflow re-activates on Final State when using OnWorkflowItemChanged Event
Windows WorkFlow Foundation: Cannot add a new state in between two existing states.
Within VS2008, can't drill down into a workflow without checking it out
SQLTrackingService tracks incorrect WorkflowInstanceEvent order?
XAML Workflows, Property Bindings and Conditions sample
Tracking query timeouts
Insert activity during PreFilterProperties
Passing data from Activity to Activity in XAML Workflows
Problem with x:Class and CreateWorkflow
Activity property resets back to default inside while activity
Designer does not maintain scroll position returning back from eventdrivenactivity to root designer surface in WF 3

Categories

MSDN
Using Forums
Microsoft Azure
Windows Phone Dev Center
Architecture
Machine Translation an...
Microsoft Robotics
SQL Server
Feedback and Discussions
Orchard
ScriptJunkie
Microsoft Research
Visio 2010
Microsoft Atlas API: D...
Bing Ads API: Development
Other Forums
Archived Forums E-H
Archived Forums T-U
Microsoft Partner Center
Cortana
Announcements for all ...
Where is the Forum For…?
Off-Topic Posts (Do No...
Visual Studio Setup an...
MSBuild
Application Insights (AI)
Tools for Apache Cordova
Register and Manage Ac...
General Windows Deskto...
Windows Desktop Sideba...
Windows Imaging Compon...
Development with the W...
Message Analyzer
Excel for Developers
Outlook for Developers
SharePoint 2013 - Gene...
SharePoint 2013 - Usin...
SharePoint 2010 - Search
Pricing & Billing
Azure Virtual Machines
Machine Learning
Cognitive Services
Azure Time Series Insi...
Windows Communication ...
Team Foundation Server...
Team Foundation Server...
Visual FoxPro General
BizTalk Server Adapter...
BizTalk Server EDI and...
Commerce Server 2007
WCF Data Services
JScript Native
Internet Explorer Web ...
ISV Open Discussions
Training and Certifica...
SQL Server Integration...
SQL Server Database En...
Database Mirroring
SQL Server Application...
Power Pivot
SQL Server 2012 SQL To...
Windows Live  Spaces: ...
Script Junkie Discussion
Developing for the Mob...
Bing Maps WPF, WP7/8/8...
Bing Maps REST, SOAP, ...
Bing Ads API: Development
Microsoft Lync Server ...
Programming Silverligh...
Silverlight Controls a...
Managed Extensibility ...
Performance Profiling ...
MVVM / ViewModel Patte...
Expression Design
Expression Studio
Expression Web and Sup...
Retired InfoPath Forms...
Retired SharePoint Acc...
Project Online General...
.NET Framework 4 Appli...
.NET Framework 4 setup...
Audio API and Programm...
Azure Startups
Building Windows Store...
Charts & Reports in th...
Doloto
DNS and Traffic Manager
Game Technologies: Aud...
Managed Extensibility ...
Office Live Small Busi...
Popfly Bugs and Sugges...
Search Server: Federation
SQL Server 2014 In-Mem...
Team Foundation Server...
Visual Basic Power Packs
Visual C# IDE
Visual Studio 2008 Exp...
Visual Studio Database...
Visual Studio Guidance...
Visual Studio Lab Mana...
WCF Data Services (Pre...
Web Development in Vis...
Windows CardSpace ('In...
Windows Live Data Deve...
Ad Revenue, Payout & T...
Windows Phone Preview SDK
.NET Native Preview
SQL Server 2016 Preview

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile