SPWorkflowDataSource Class
System.Object
System.Web.UI.Control
System.Web.UI.DataSourceControl
Microsoft.SharePoint.WebControls.SPWorkflowDataSource
System.Web.UI.Control
System.Web.UI.DataSourceControl
Microsoft.SharePoint.WebControls.SPWorkflowDataSource
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] public sealed class SPWorkflowDataSource : DataSourceControl, IDataSource, IDisposable
SPWorkflowDataSource
Description
The Microsoft.SharePoint.WebControls.SPWorkflowDataSource class inherits from the System.Web.UI.IDataSource for abstract data source representation. As well, it inherits from System.Web.UI.DataSourceControl which is the base class for data source controls. The specialized attributes of the control can be found in the extended properties that are offered in order to support SharePoint and Workflow specific functions, such as granular parameter passing as demonstrated through the exposure of associated SPListItem and SPList ID’s.
As SPWorkflowDataSource inherits from the IDataSource interface in order in order to support the data binding infrastructure, it provides appropriate overrides for GetView, which will select a particular view, and GetViewNames, which will specify how many DataSourceViews are exposed as well as their corresponding names.
The Usage Scenario
The primary usage of SPWorkflowDataSource is internal. It can be immediately studied by associating a workflow to a SPList within SharePoint Designer as a datasource. This will parse the results of the SPWorkflowDataSource using XSLT.
However, if custom behavior is desired, it is possible to use SPWorkflowDataSource in combination with sister classes, namely the SPWorkflowDataSourceView and DataSourceSelectArguments, in order to build custom select statements.
In the below, I am demonstrating a global IDataSource object which will firstly be tested for type by comparing against the SPWorkflowDataSource type. If the datasource conforms, it can be used to instantiate a new SPWorkflowDataSourceView object. By passing in a string.Empty argument into the GetView method we will receive the default view for query. Following, a new DataSourceSelectArguments object can be used in order to pass in arguments, and the event handlers (empty in the below, however can contain logic) can customize the SPWorkflowDataSourceView object that is returned.
C# Code Example
private IDataSource _ds;
private SPWorkflowDataSourceView GetAndSelectFromDS()
{
if (_ds != null)
{
if (_ds is SPWorkflowDataSource)
{
SPWorkflowDataSourceView view = _ds.GetView(string.Empty) as SPWorkflowDataSourceView;
DataSourceSelectArguments arguments = new DataSourceSelectArguments();
if (view != null)
{
view.Select(arguments, DataSelected);
return view;
}
}
}
return null;
}
public void DataSelected(IEnumerable data)
{
// customize after event behavior
}
Visual Basic .NET Code Example
Private _ds As IDataSource
Private Function GetAndSelectFromDS() As SPWorkflowDataSourceView
If _ds IsNot Nothing Then
If TypeOf _ds Is SPWorkflowDataSource Then
Dim view As SPWorkflowDataSourceView = TryCast(_ds.GetView(String.Empty), SPWorkflowDataSourceView)
Dim arguments As New DataSourceSelectArguments()
If view IsNot Nothing Then
view.[Select](arguments, DataSelected)
Return view
End If
End If
End If
Return Nothing
End Function
Public Sub DataSelected(ByVal data As IEnumerable)
' customize after event behavior
End Sub
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
The Microsoft.SharePoint.WebControls.SPWorkflowDataSource class inherits from the System.Web.UI.IDataSource for abstract data source representation. As well, it inherits from System.Web.UI.DataSourceControl which is the base class for data source controls. The specialized attributes of the control can be found in the extended properties that are offered in order to support SharePoint and Workflow specific functions, such as granular parameter passing as demonstrated through the exposure of associated SPListItem and SPList ID’s.
As SPWorkflowDataSource inherits from the IDataSource interface in order in order to support the data binding infrastructure, it provides appropriate overrides for GetView, which will select a particular view, and GetViewNames, which will specify how many DataSourceViews are exposed as well as their corresponding names.
The Usage Scenario
The primary usage of SPWorkflowDataSource is internal. It can be immediately studied by associating a workflow to a SPList within SharePoint Designer as a datasource. This will parse the results of the SPWorkflowDataSource using XSLT.
However, if custom behavior is desired, it is possible to use SPWorkflowDataSource in combination with sister classes, namely the SPWorkflowDataSourceView and DataSourceSelectArguments, in order to build custom select statements.
In the below, I am demonstrating a global IDataSource object which will firstly be tested for type by comparing against the SPWorkflowDataSource type. If the datasource conforms, it can be used to instantiate a new SPWorkflowDataSourceView object. By passing in a string.Empty argument into the GetView method we will receive the default view for query. Following, a new DataSourceSelectArguments object can be used in order to pass in arguments, and the event handlers (empty in the below, however can contain logic) can customize the SPWorkflowDataSourceView object that is returned.
C# Code Example
private IDataSource _ds;
private SPWorkflowDataSourceView GetAndSelectFromDS()
{
if (_ds != null)
{
if (_ds is SPWorkflowDataSource)
{
SPWorkflowDataSourceView view = _ds.GetView(string.Empty) as SPWorkflowDataSourceView;
DataSourceSelectArguments arguments = new DataSourceSelectArguments();
if (view != null)
{
view.Select(arguments, DataSelected);
return view;
}
}
}
return null;
}
public void DataSelected(IEnumerable data)
{
// customize after event behavior
}
Visual Basic .NET Code Example
Private _ds As IDataSource
Private Function GetAndSelectFromDS() As SPWorkflowDataSourceView
If _ds IsNot Nothing Then
If TypeOf _ds Is SPWorkflowDataSource Then
Dim view As SPWorkflowDataSourceView = TryCast(_ds.GetView(String.Empty), SPWorkflowDataSourceView)
Dim arguments As New DataSourceSelectArguments()
If view IsNot Nothing Then
view.[Select](arguments, DataSelected)
Return view
End If
End If
End If
Return Nothing
End Function
Public Sub DataSelected(ByVal data As IEnumerable)
' customize after event behavior
End Sub
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
- 6/3/2010
- Adam Buenz - MVP