This topic has not yet been rated - Rate this topic

AssignToEmailMessage Class

Represents a message that e-mail will be sent to users who are listed in the AssignedTo field.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class AssignToEmailMessage : FormComponent
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
AssignToEmailMessage
Description 

The Microsoft.SharePoint.WebControls.AssignToEmailMessage class inherits from the Microsoft.SharePoint.WebControls.FormComponent class which is the foundational control for form and field rendering controls. AssignToEmailMessage is heavily related to SPList objects since each SPList has a Boolean SPList.EnableAssignToEmail property which is responsible for email notification configuration. Depending on this property will toggle AssignToEmailMessage control visibility. 

The most ordinary scenario to study the behavior is within a task list when you require to cease the default messages for task assignments that are sent. 

The AssignToEmailMessage class works in a very simple fashion, checking the current list instance for whether the SPList.EnableAssignToEmail property is set to true in order to toggle visibility. 

The message is rendered out by default is:

“The content of this item will be sent as an e-mail message to the person or group assigned to the item”.

which will be rendered to the output stream by retrieving the string out of the SharePoint resource files. 

Usage Scenario

The primary usage of the AssignToEmailMessage class is internal since it is a foundational list component. However, since the class is not sealed it is possible to use it for dervitation, or if rendering out its default message is desired within a control.

In the below, I am firstly instantiating a new AssignToEmailMessage object, toggling it’s visibility, and adding it to the current instance control collection. As well, the ExampleMessageExtension class inherits from the AssignToEmailMessage class and overrides the Render method in order to provide a literal string to write to the output stream.

C# Code Example

public class ExampleWebPart : WebPart
{
protected override void CreateChildControls()
{
AssignToEmailMessage message = new AssignToEmailMessage();
message.Visible = true;
Controls.Add(message);
}
}

public class ExampleMessageExtension : AssignToEmailMessage
{
protected override void Render(HtmlTextWriter output)
{
output.Write("after this occurs, the inherited render will perform");
base.Render(output);
}
}

Visual Basic .NET Code Example

Public Class ExampleWebPart
Inherits WebPart
Protected Overloads Overrides Sub CreateChildControls()
Dim message As New AssignToEmailMessage()
message.Visible = True
Controls.Add(message)
End Sub
End Class
Public Class ExampleMessageExtension
Inherits AssignToEmailMessage
Protected Overloads Overrides Sub Render(ByVal output As HtmlTextWriter)
output.Write("after this occurs, the inherited render will perform")
MyBase.Render(output)
End Sub
End Class

Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com