项目作者: ChrisPritchard

项目描述 :
A set of C# classes for SharePoint 2007/2010 that allow fluent-style querying of content (using generated CAML), programmatic content creation and programmatic taxonomy creation.
高级语言: C#
项目地址: git://github.com/ChrisPritchard/FluentSharepoint.git
创建时间: 2018-07-28T01:03:58Z
项目社区:https://github.com/ChrisPritchard/FluentSharepoint

开源协议:MIT License

下载


FluentSharepoint

A set of C# classes for SharePoint 2007/2010 that allow fluent-style querying of content (using generated CAML), programmatic content creation and programmatic taxonomy creation.

Recorded here for posterity, and for the use of any poor souls that have to work with these systems still and have the leeway to run server-side code.

The three classes should be extracted as needed and imported into your own utility console applications - this repo is not executable or referenceable by itself.

All code was written around the .NET Framework 3.0-3.5 era. I was particularly enamoured by extension methods and LINQ at the time, and it shows.

FluentCamlQueries.cs

CAML is a list filtering language for SharePoint 2007/2010. You construct an XML ‘query’ that is then applied to a list to get a subset of results, ordered and with property trimming as necessary. As CAML is a bit complex, especially when it comes to public field names and their autogenerated internal names, I created this class to allow generating valid CAML in a more fluent fashion for both my own edification and that of the more novice developers I worked with.

An example of use:

  1. var results = list.Query()
  2. .When("Fund").IsEqualTo("Fellowships")
  3. .And.When("Title").Contains("Environmental")
  4. .WithViewContaining("Title")
  5. .And("Contract").Only
  6. .OrderByAscendingInternalName("Modified", true) // using internal name here
  7. .Finally
  8. .GetResultsAsList();

FluentCreationExtensions.cs

A lot of the sites I worked on at the time I wrote this required a good deal of content to be ‘pre-created’. Whether that be ContentTypes (it was always Content Types), Lists, Roles, etc. This can be done a number of ways, and the way that is NOT recommended but which always worked, was programmatically using the SharePoint object model. Enter this class, that allowed you to create such content in a safe, fluent fashion.

All methods are prefixed with Ensure: this would allow the process to be re-runnable, important for iterative development: it would create a piece of content (like a content type or list) only if it wasnt there already.

FluentCreationTaxonomyExtensions.cs

This class requires SP2010. With 2010 came the concept of Taxonomy (which wrecked the SP vendor industry in my opinion, but was good for SharePoint as a whole (wrecking the vendor industry was probably also good for SP as a whole)). And with Taxonomy, came my fluent class.