SharePointDataSource<T>

The SharePointDataSource<T> class acts as the gateway to a SharePoint list in order to write LINQ queries against it. The generic parameter T should reference an entity type generated by SpMetal.

Constructors

Three constructors are available on SharePointDataSource<T>:

public SharePointDataSource(Uri siteUrl);
public SharePointDataSource(SPList list);
public SharePointDataSource(SPSite site);
  • The first constructor is used to connect to a SharePoint list using the SharePoint web services where siteUrl points to the SharePoint web site root. The name of the list is retrieved from the List property on the entity ListAttribute. Credentials can be set using the Credentials properties as explained further on.
  • The second constructor is used to connect to a SharePoint list directly using the SharePoint object model. This will only work if you run the code on the machine hosting the SharePoint list.
  • The third constructor is used to connect to a SharePoint list directly using the SharePoint object model; the SPList object will be retrieved from the site's root web automatically using the Path property of the ListAttribute. This will only work if you run the code on the machine hosting the SharePoint list.

Configuration properties

SharePointDataSource<T> has three properties you can set to configure the data providers:
  • Log can be set to a System.IO.TextWriter object in order to log diagnostic information about the CAML query sent to the server when executing a query. Logging will be triggered when results are fetched, i.e. whenever iteration is performed on the data source (e.g. using foreach).
  • Credentials can only be used if the data source is connecting to the SharePoint list over web services. It's used to specify the credentials used for authentication with the web service. If not set, the DefaultNetworkCredentials from the System.Net.CredentialCache will be used.
  • CheckListVersion, if set to true, enforces a list version check whenever the SharePoint list is queried. Such a version check can be used to make sure queries are only executed against a list if it matches the version number kept on the entity type using the ListAttribute's Version property. Needless use of this feature will affect performance negatively.

Methods

All methods except for Dispose on the SharePointDataSource<T> are implementations of IQuerable<T> methods and are not intended to be used directly from your application.

As a best practice, it's recommended to use SharePointDataSource<T> objects in combination with the using statement:

using (var users = new SharePointDataSource<User>())
{
   //write queries here
}

Last edited Apr 21, 2007 at 9:46 PM by bdesmet, version 2

Comments

No comments yet.