LibraryBuilder

LibraryBuilder is an utility class (wrapper) that helps out with creating SPLists and SPDocumentLibraries.
The following properties exist:
  • SPWeb Site { get; set; }
  • string Title { get; set; }
  • string Description { get; set; }
  • string Name { get; set; }
  • bool SupportsVersioning { get; set; }
  • bool CanBeCrawled { get; set; }
  • string Template { get; set; }
  • SPListTemplateType TemplateType { get; set; }
  • List<SPContentTypeId> SupportedContentTypes { get; private set; }


They can be set either through standard property assignment or by using the fluent interface implementation.

Example of property setter style:
var builder = new LibraryBuilder
{
                Site = root,
                Name = "mydoclib",
                Title = "My Doc Lib",
                Description = "...",
                TemplateType = SPListTemplateType.DocumentLibrary
};

builder.SupportedContentTypes.Add(SPBuiltInContentTypeId.XMLDocument); 

// here is where the SPDocumentLibrary is created (or updated).
SPDocumentLibrary lib = builder.Cast<SPDocumentLibrary>();

Example of fluent interface (method chaining) style:
var builder = new LibraryBuilder(root, "mytasklist")
                            .ContentTypeSupportFor(SPBuiltInContentTypeId.Task)
                            .Description("This is an instance of mylib")
                            .CanBeCrawled(false)
                            .SupportsVersioning(true)
                            .Title("My Task List");

// here is where the SPList is created (or updated).
SPList list = builder.Cast<SPList>();

The librarybuilder class can also provide logging information by exposing an event. Here is how you can benefit from that:
builder.Logging += (sender, args) =>
{
  WriteToLogSomeWhere(args.Value);
};

Last edited Feb 16, 2010 at 3:10 PM by jole, version 6

Comments

No comments yet.