This topic has not yet been rated - Rate this topic

SPWorkflowDataSourceView Class

System.Object
  System.Web.UI.DataSourceView
    Microsoft.SharePoint.WebControls.SPWorkflowDataSourceView

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 sealed class SPWorkflowDataSourceView : DataSourceView, 
	IDisposable
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
SPWorkflowDataSourceView
Description

The Microsoft.SharePoint.WebControls.SPWorkflowDataSourceView sealed class inherits from System.Web.UI.DataSourceView, which serves as the base class for derived data source view classes. In the case of the SPWorkFlowDataSourceView class, the DataSource is of type Microsoft.SharePoint.WebControls.SPWorkflowDataSource. SPWorkFlowDataSource finds heavy representation when using SharePoint Designer (SPD) during creation and association of a Workflow to a list. SPWorkflowDataSource provides the required data source and associated parameters in order to create the SharePoint generated forms relevant to the workflow. Developers most frequently encounter the SPWorkflowDataSource object when attempting to port a SPD provided Workflow into the Visual Studio .NET environment.

SPWorkflowDataSourceView provides the mechanisms to massage data out of an arbitrary SPWorkflowDataSource object, called by the SPWorkflowDataSource.GetView method. Most importantly, within the class the ExecuteSelect method is overridden with the use of Microsoft.SharePoint.Workflow.SPWorkflowAssociation object, in order to support an IEnumerable collection of values to support foreach programming semantic.

Usage Scenario

The primary usage of SPWorkflowDataSourceView is either automated through the use of SPD or used internally by the API for workflow support. Since the SPWorkflowDataSource inherits from the DataSourceView class, it is possible to use it as an orthodox class as that type however special consideration is given to the class to account for SharePoint workflow attributes such as the SPList.Id and SPListItem.Id.

In the below, MyClass is deriving from FormComponent. Three objects are being create, a SPGridView, a SPWorkFlowDataSource with its SPWorkflowDataSource.ItemId being set to the ItemContext.ItemId and the SPWorkflowDataSource.ListId set to the ItemContext.ListId. This object after being created is then used to pass into the constructor of new SPWorkFlowDataSourceView object. This object is then used in order to set the DataSource of the SPGridView object, which is subseqnutnly, databinded through the use of SPGridView.DataBind and then added to the current instance control collection.

C# Code Example

public class MyClass : FormComponent
{
protected override void CreateChildControls()
{
SPGridView view = new SPGridView();
SPWorkflowDataSource myDataSource = new SPWorkflowDataSource();
myDataSource.ItemId = ItemContext.ItemId;
myDataSource.ListId = ItemContext.ListId.ToString();
SPWorkflowDataSourceView myDataSourceView = new SPWorkflowDataSourceView(myDataSource);
view.DataSource = myDataSourceView;
view.DataBind();
Controls.Add(view);
}


VB.NET Code Example

Public Class [MyClass]
Inherits FormComponent
Protected Overloads Overrides Sub CreateChildControls()
Dim view As New SPGridView()
Dim myDataSource As New SPWorkflowDataSource()
myDataSource.ItemId = ItemContext.ItemId
myDataSource.ListId = ItemContext.ListId.ToString()
Dim myDataSourceView As New SPWorkflowDataSourceView(myDataSource)
view.DataSource = myDataSourceView
view.DataBind()
Controls.Add(view)
End Sub
End Class

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