/// <summary> /// Used to create a custom document library and Contoso Content type /// </summary> /// <param name="ctx">The authenticated ClientContext</param> /// <param name="library">The Library to create</param> public void CreateContosoDocumentLibrary(ClientContext ctx, Library library) { //Check the fields if (!ctx.Web.FieldExistsById(FLD_CLASSIFICATION_ID)) { ctx.Web.CreateTaxonomyField(FLD_CLASSIFICATION_ID, FLD_CLASSIFICATION_INTERNAL_NAME, FLD_CLASSIFICATION_DISPLAY_NAME, FIELDS_GROUP_NAME, TAXONOMY_GROUP, TAXONOMY_TERMSET_CLASSIFICATION_NAME); } //check the content type if (!ctx.Web.ContentTypeExistsById(CONTOSODOCUMENT_CT_ID)) { ctx.Web.CreateContentType(CONTOSODOCUMENT_CT_NAME, CT_DESC, CONTOSODOCUMENT_CT_ID, CT_GROUP); } //associate fields to content types if (!ctx.Web.FieldExistsByNameInContentType(CONTOSODOCUMENT_CT_NAME, FLD_CLASSIFICATION_INTERNAL_NAME)) { ctx.Web.AddFieldToContentTypeById(CONTOSODOCUMENT_CT_ID, FLD_CLASSIFICATION_ID.ToString(), false); } CreateLibrary(ctx, library, CONTOSODOCUMENT_CT_ID); }
/// <summary> /// Used to create a custom document library and Contoso Content type /// </summary> /// <param name="ctx">The authenticated ClientContext</param> /// <param name="library">The Library to create</param> public void CreateContosoDocumentLibrary(ClientContext ctx, Library library) { //Check the fields if (!ctx.Web.FieldExistsById(FLD_CLASSIFICATION_ID)) { TermStore termStore = GetDefaultTermStore(ctx.Web); if (termStore == null) { throw new NullReferenceException("The default term store is not available."); } // get the term group and term set TermGroup termGroup = termStore.Groups.GetByName(TAXONOMY_GROUP); TermSet termSet = termGroup.TermSets.GetByName(TAXONOMY_TERMSET_CLASSIFICATION_NAME); ctx.Load(termStore); ctx.Load(termSet); ctx.ExecuteQuery(); TaxonomyFieldCreationInformation fldCreate = new TaxonomyFieldCreationInformation() { Id = FLD_CLASSIFICATION_ID, InternalName = FLD_CLASSIFICATION_INTERNAL_NAME, DisplayName = FLD_CLASSIFICATION_DISPLAY_NAME, Group = FIELDS_GROUP_NAME, TaxonomyItem = termSet, }; ctx.Web.CreateTaxonomyField(fldCreate); } //check the content type if (!ctx.Web.ContentTypeExistsById(CONTOSODOCUMENT_CT_ID)) { ctx.Web.CreateContentType(CONTOSODOCUMENT_CT_NAME, CT_DESC, CONTOSODOCUMENT_CT_ID, CT_GROUP); } //associate fields to content types if (!ctx.Web.FieldExistsByNameInContentType(CONTOSODOCUMENT_CT_NAME, FLD_CLASSIFICATION_INTERNAL_NAME)) { ctx.Web.AddFieldToContentTypeById(CONTOSODOCUMENT_CT_ID, FLD_CLASSIFICATION_ID.ToString(), false); } CreateLibrary(ctx, library, CONTOSODOCUMENT_CT_ID); }
/// <summary> /// Helper Member to get the libary for the ItemAdding Rer /// </summary> /// <returns></returns> private Library GetLibaryInformationItemAdding() { Library _libraryToCreate = new Library() { Title = "AutoTaggingSampleItemAdding", Description = "This is a demo showing how to use ItemAdding ReR", VerisioningEnabled = false }; return _libraryToCreate; }
/// <summary> /// Helper Class to create document libraries /// </summary> /// <param name="ctx">The ClientContext, that must be valide</param> /// <param name="library">Domain Object for the Library</param> /// <param name="associateContentTypeID">The Content Type ID to add to the list.</param> private void CreateLibrary(ClientContext ctx, Library library, string associateContentTypeID) { if (!ctx.Web.ListExists(library.Title)) { ctx.Web.CreateList(ListTemplateType.DocumentLibrary, library.Title, false); List _list = ctx.Web.GetListByTitle(library.Title); if (!string.IsNullOrEmpty(library.Description)) { _list.Description = library.Description; } if (library.VerisioningEnabled) { _list.EnableVersioning = true; } _list.ContentTypesEnabled = true; _list.RemoveContentTypeByName("Document"); _list.Update(); ctx.Web.AddContentTypeToListById(library.Title, associateContentTypeID, true); ctx.Web.Context.ExecuteQuery(); } else { throw new Exception("A list, survey, discussion board, or document library with the specified title already exists in this Web site. Please choose another title."); } }
/// <summary> /// Creates a custom document library and IT Document Content Type /// </summary> /// <param name="ctx">The authenticated ClientContext</param> /// <param name="library">The Library to create</param> public void CreateITDocumentLibrary(ClientContext ctx, Library library) { //Check the fields if (!ctx.Web.FieldExistsById(FLD_BUSINESS_UNIT_ID)) { //ctx.Web.CreateField(FLD_BUSINESS_UNIT_ID, // FLD_BUSINESS_UNIT_INTERNAL_NAME, // FieldType.Text, // FLD_BUSINESS_UNIT_DISPLAY_NAME, // FIELDS_GROUP_NAME); FieldCreationInformation fldCreate = new FieldCreationInformation(FieldType.Text) { Id = FLD_BUSINESS_UNIT_ID, InternalName = FLD_BUSINESS_UNIT_INTERNAL_NAME, DisplayName = FLD_BUSINESS_UNIT_DISPLAY_NAME, Group = FIELDS_GROUP_NAME }; ctx.Web.CreateField(fldCreate); } //check the content type if (!ctx.Web.ContentTypeExistsById(ITDOCUMENT_CT_ID)) { ctx.Web.CreateContentType(ITDOCUMENT_CT_NAME, CT_DESC, ITDOCUMENT_CT_ID, CT_GROUP); } //associate fields to content types if (!ctx.Web.FieldExistsByNameInContentType(ITDOCUMENT_CT_NAME, FLD_BUSINESS_UNIT_INTERNAL_NAME)) { ctx.Web.AddFieldToContentTypeById(ITDOCUMENT_CT_ID, FLD_BUSINESS_UNIT_ID.ToString(), false); } CreateLibrary(ctx, library, ITDOCUMENT_CT_ID); }
/// <summary> /// Creates a custom document library and IT Document Content Type /// </summary> /// <param name="ctx">The authenticated ClientContext</param> /// <param name="library">The Library to create</param> public void CreateITDocumentLibrary(ClientContext ctx, Library library) { //Check the fields if (!ctx.Web.FieldExistsById(FLD_BUSINESS_UNIT_ID)) { ctx.Web.CreateField(FLD_BUSINESS_UNIT_ID, FLD_BUSINESS_UNIT_INTERNAL_NAME, FieldType.Text, FLD_BUSINESS_UNIT_DISPLAY_NAME, FIELDS_GROUP_NAME); } //check the content type if (!ctx.Web.ContentTypeExistsById(ITDOCUMENT_CT_ID)) { ctx.Web.CreateContentType(ITDOCUMENT_CT_NAME, CT_DESC, ITDOCUMENT_CT_ID, CT_GROUP); } //associate fields to content types if (!ctx.Web.FieldExistsByNameInContentType(ITDOCUMENT_CT_NAME, FLD_BUSINESS_UNIT_INTERNAL_NAME)) { ctx.Web.AddFieldToContentTypeById(ITDOCUMENT_CT_ID, FLD_BUSINESS_UNIT_ID.ToString(), false); } CreateLibrary(ctx, library, ITDOCUMENT_CT_ID); }