Beispiel #1
0
        /// <summary>
        /// Used to create a custom document library and Contoso Content type
        /// </summary>
        /// <param name="ctx">The client context that has be authenticated</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);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a custom document library and IT Document Content Type
        /// </summary>
        /// <param name="ctx">The client context that has be authenticated</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);
        }
Beispiel #3
0
        /// <summary>
        /// Used to create a custom document library and Contoso Content type
        /// </summary>
        /// <param name="ctx">The client context that has be authenticated</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)){

                // Get access to the right term set
                TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(ctx.Web.Context);
                TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
                TermGroup termGroup = termStore.Groups.GetByName(TAXONOMY_GROUP);
                TermSet termSet = termGroup.TermSets.GetByName(TAXONOMY_TERMSET_CLASSIFICATION_NAME);
                ctx.Web.Context.Load(termStore);
                ctx.Web.Context.Load(termSet);
                ctx.Web.Context.ExecuteQueryRetry();

                TaxonomyFieldCreationInformation fieldCI = 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(fieldCI);
            }
            
            //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.AddFieldToContentTypeByName(CONTOSODOCUMENT_CT_NAME, 
                                                    FLD_CLASSIFICATION_ID);
            }
            CreateLibrary(ctx, library, CONTOSODOCUMENT_CT_ID);
          
        }
Beispiel #4
0
        private Library GetLibraryToCreate()
        {
            Library _libraryToCreate = new Library()
            {
                Title = this.LibraryName.Value,
                Description = this.LibraryDescription.Value,
                VerisioningEnabled = this.onetidVersioningEnabledYes.Checked
            };

            return _libraryToCreate;
        }
Beispiel #5
0
        /// <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.AddList(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.Update();
                ctx.Web.AddContentTypeToListById(library.Title, associateContentTypeID, true);
                //we are going to remove the default Document Content Type
                _list.RemoveContentType(ContentTypeManager.DEFAULT_DOCUMENT_CT_NAME);
                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.");
            }
        }
Beispiel #6
0
        /// <summary>
        /// Creates a custom document library and IT Document Content Type
        /// </summary>
        /// <param name="ctx">The client context that has be authenticated</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)){
                FieldCreationInformation field = 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(field);
            }
            //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.AddFieldToContentTypeByName(ITDOCUMENT_CT_NAME, FLD_BUSINESS_UNIT_ID);
            }
            CreateLibrary(ctx, library, ITDOCUMENT_CT_ID);
        }
Beispiel #7
0
        /// <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.Update();
                // Add content type tot eh list
                ctx.Web.AddContentTypeToListById(library.Title, associateContentTypeID);
                //Set default content type as with the one which we jus added
                ctx.Web.SetDefaultContentTypeToList(library.Title, associateContentTypeID);
                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.");
            }
        }