Creating Custom Workflow Activities for SharePoint Server 2007 Using Visual Studio 2008
Office 2007
Summary: Learn how to create a custom activity for Microsoft Office SharePoint Server 2007 to send an e-mail message that has an attachment.
Applies to: Microsoft Office SharePoint Server 2007, Microsoft Visual Studio 2008
Mike Rand, 3Sharp
June 2008
Help
Hi
Thanks a lot for Your Great Article (Creating Custom workflow Activities for Sharepoint) .
I simulated your activities and watched your Film , And you Mentioned to (publicstaticDependencyProperty FromProperty
)
.when i Built my project i get 25 error that all of errors mention to below error :
Error 1 The name 'SendMailWithAttachmentsTest' does not exist in the current context c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity.cs 67 50
or this error
Error 24 The type or namespace name 'SendMailWithAttachmentsTest' could not be found (are you missing a using directive or an assembly reference?) c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity.cs 50 52
.
I dont know maybe i must add some namespace or something like that.
Who Can Help me
Thanks.
Thanks a lot for Your Great Article (Creating Custom workflow Activities for Sharepoint) .
I simulated your activities and watched your Film , And you Mentioned to (publicstaticDependencyProperty FromProperty
=
DependencyProperty.Register( "From", typeof(string), typeof(SendMailWithAttachmentsTest));)
.when i Built my project i get 25 error that all of errors mention to below error :
Error 1 The name 'SendMailWithAttachmentsTest' does not exist in the current context c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity.cs 67 50
or this error
Error 24 The type or namespace name 'SendMailWithAttachmentsTest' could not be found (are you missing a using directive or an assembly reference?) c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity\SendMailWithAttachmentActivity.cs 50 52
.
I dont know maybe i must add some namespace or something like that.
Who Can Help me
Thanks.
[tfl - 24 06 10] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
- 12/2/2009
- DearABI
- 6/24/2010
- Thomas Lee
Here's Fix
Hi,Thomas Lee. I've benn confused as you. And now, here's source for you.
It's source for SendMailWithAttachmentActivity.cs, and leave SendMailWithAttachmentActivity.Designer.cs as it is.
I hop it helps.
-----------------------------------------------SendMailWithAttachmentActivity.cs START-----------------------------------------------
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Net.Mail;
namespace SendMailWithAttachmentActivity
{
public partial class SendMailWithAttachmentActivity : Activity
{
public SendMailWithAttachmentActivity()
{
InitializeComponent();
}
#region "Fields"
public static DependencyProperty ToProperty =
DependencyProperty.Register( "To",typeof(string),typeof(SendMailWithAttachmentActivity));
public static DependencyProperty FromProperty =
DependencyProperty.Register("From", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty CcProperty =
DependencyProperty.Register("Cc", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty SubjectProperty =
DependencyProperty.Register("Subject", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty BodyProperty =
DependencyProperty.Register("Body", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty AttachmentProperty =
DependencyProperty.Register("Attachment", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty SmtpServerProperty =
DependencyProperty.Register("SmtpServer", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty InvokeEvent =
DependencyProperty.Register("Invoke", typeof(EventHandler), typeof(SendMailWithAttachmentActivity));
#endregion
#region "Propertities"
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter any e-mail recipients, separated by semicolons")]
public string To
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.ToProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.ToProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter the e-mail sender")]
public string From
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.FromProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.FromProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
[Browsable(true)]
[Description("Enter any carbon copy recipients, separated by semicolons")]
public string Cc
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.CcProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.CcProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter the e-mail subject")]
public string Subject
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.SubjectProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.SubjectProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
[Browsable(true)]
[Description("Enter the body text of the e-mail")]
public string Body
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.BodyProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.BodyProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
[Browsable(true)]
[Description("Enter an attachment file path")]
public string Attachment
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.AttachmentProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.AttachmentProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter the Smtp Server for the email")]
[DisplayName("Smtp Server")]
public string SmtpServer
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.SmtpServerProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.SmtpServerProperty, value); }
}
[DescriptionAttribute("Invoke")]
[CategoryAttribute("Invoke Category")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public event EventHandler Invoke
{
add
{
base.AddHandler(SendMailWithAttachmentActivity.InvokeEvent, value);
}
remove
{
base.RemoveHandler(SendMailWithAttachmentActivity.InvokeEvent, value);
}
}
#endregion
#region "Event"
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
// Raise Invoke Event to execute custom code in the workflow.
this.RaiseEvent(SendMailWithAttachmentActivity.InvokeEvent, this, EventArgs.Empty);
// Set reference to Smtp Server.
SmtpClient smtp = new SmtpClient(SmtpServer);
// Create mail message.
MailMessage msg = new MailMessage();
msg.To.Add(To);
msg.From = new MailAddress(From);
if (!String.IsNullOrEmpty(Cc))
{
msg.CC.Add(Cc);
}
if (!String.IsNullOrEmpty(Subject))
{
msg.Subject = Subject;
}
if (!String.IsNullOrEmpty(Body))
{
msg.Body = Body;
}
if (!String.IsNullOrEmpty(Attachment))
{
msg.Attachments.Add(new Attachment(Attachment));
}
// Send the e-mail.
smtp.Send(msg);
// Indicate that the activity has completed.
return ActivityExecutionStatus.Closed;
}
#endregion
}
}
-----------------------------------------------SendMailWithAttachmentActivity.cs END-----------------------------------------------
It's source for SendMailWithAttachmentActivity.cs, and leave SendMailWithAttachmentActivity.Designer.cs as it is.
I hop it helps.
-----------------------------------------------SendMailWithAttachmentActivity.cs START-----------------------------------------------
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Net.Mail;
namespace SendMailWithAttachmentActivity
{
public partial class SendMailWithAttachmentActivity : Activity
{
public SendMailWithAttachmentActivity()
{
InitializeComponent();
}
#region "Fields"
public static DependencyProperty ToProperty =
DependencyProperty.Register( "To",typeof(string),typeof(SendMailWithAttachmentActivity));
public static DependencyProperty FromProperty =
DependencyProperty.Register("From", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty CcProperty =
DependencyProperty.Register("Cc", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty SubjectProperty =
DependencyProperty.Register("Subject", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty BodyProperty =
DependencyProperty.Register("Body", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty AttachmentProperty =
DependencyProperty.Register("Attachment", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty SmtpServerProperty =
DependencyProperty.Register("SmtpServer", typeof(string), typeof(SendMailWithAttachmentActivity));
public static DependencyProperty InvokeEvent =
DependencyProperty.Register("Invoke", typeof(EventHandler), typeof(SendMailWithAttachmentActivity));
#endregion
#region "Propertities"
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter any e-mail recipients, separated by semicolons")]
public string To
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.ToProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.ToProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter the e-mail sender")]
public string From
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.FromProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.FromProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
[Browsable(true)]
[Description("Enter any carbon copy recipients, separated by semicolons")]
public string Cc
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.CcProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.CcProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter the e-mail subject")]
public string Subject
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.SubjectProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.SubjectProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
[Browsable(true)]
[Description("Enter the body text of the e-mail")]
public string Body
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.BodyProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.BodyProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Optional)]
[Browsable(true)]
[Description("Enter an attachment file path")]
public string Attachment
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.AttachmentProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.AttachmentProperty, value); }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[ValidationOption(ValidationOption.Required)]
[Browsable(true)]
[Description("Enter the Smtp Server for the email")]
[DisplayName("Smtp Server")]
public string SmtpServer
{
get { return ((string)(base.GetValue(SendMailWithAttachmentActivity.SmtpServerProperty))); }
set { base.SetValue(SendMailWithAttachmentActivity.SmtpServerProperty, value); }
}
[DescriptionAttribute("Invoke")]
[CategoryAttribute("Invoke Category")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public event EventHandler Invoke
{
add
{
base.AddHandler(SendMailWithAttachmentActivity.InvokeEvent, value);
}
remove
{
base.RemoveHandler(SendMailWithAttachmentActivity.InvokeEvent, value);
}
}
#endregion
#region "Event"
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
// Raise Invoke Event to execute custom code in the workflow.
this.RaiseEvent(SendMailWithAttachmentActivity.InvokeEvent, this, EventArgs.Empty);
// Set reference to Smtp Server.
SmtpClient smtp = new SmtpClient(SmtpServer);
// Create mail message.
MailMessage msg = new MailMessage();
msg.To.Add(To);
msg.From = new MailAddress(From);
if (!String.IsNullOrEmpty(Cc))
{
msg.CC.Add(Cc);
}
if (!String.IsNullOrEmpty(Subject))
{
msg.Subject = Subject;
}
if (!String.IsNullOrEmpty(Body))
{
msg.Body = Body;
}
if (!String.IsNullOrEmpty(Attachment))
{
msg.Attachments.Add(new Attachment(Attachment));
}
// Send the e-mail.
smtp.Send(msg);
// Indicate that the activity has completed.
return ActivityExecutionStatus.Closed;
}
#endregion
}
}
-----------------------------------------------SendMailWithAttachmentActivity.cs END-----------------------------------------------
- 2/10/2010
- Jhonconner
- 2/10/2010
- Jhonconner
Another failed tutorial attempt by microsoft
Does anybody has a working version of the code. As so often on msdn the published code DOES NOT WORK. I tried the suggested solution above but this does not work either still 25 errors when compiled. I wish microsoft would stop allowing broken code to be published on their so called developer center. How are you supposed to learn anything when what your learning is broke???????????????????????????????????????
[tfl - 06 02 10] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
- 1/21/2010
- clubo
- 2/6/2010
- Thomas Lee
An example of using attachments without the need for Visual Studio
I have created an example of how to work around the limitations of the SharePoint Designer Email Activity. It automatically figures out if the workflow is acting on a file or listitem with attachments and then attaches it all to an email.
http://www.muhimbi.com/blog/2009/12/send-rich-emails-with-attachments-from.html
It also allows the specification of a from and BCC address.
- 12/29/2009
- Jeroen Ritmeijer
solution
Hi,
Just replace the SendMailWithAttachmentsTest with SendMailWithAttachmentActivity and it should be ok :) This is basically the type that is registering the dependency properties and in your case it is SendMailWithAttachmentActivity.
Have a nice time
Just replace the SendMailWithAttachmentsTest with SendMailWithAttachmentActivity and it should be ok :) This is basically the type that is registering the dependency properties and in your case it is SendMailWithAttachmentActivity.
Have a nice time
- 12/2/2009
- DearABI
How can I use this as a custom activity for use in SharePoint Designer 2007
I was wondering how I would be able to use this great example for a custom activity. There is an example in this link::: http://msdn.microsoft.com/en-us/library/bb629922.aspx but it uses Visual Studio 2005, I'm currently using Visual Studio 2008. It also doesn't really have a very good description on what needs to be done.
Does anyone have a solution to this? Or maybe point me in the right direction.
Thanks
- 1/8/2009
- sotelo
Note:
