Пример #1
0
        /// <summary>
        /// Assigns field values for specified content types to the specified matter (document library).
        /// </summary>
        /// <param name="clientContext">SP client context</param>
        /// <param name="contentTypeCollection">Collection of content types</param>
        /// <param name="matterList">List containing matters</param>
        /// <param name="matterMetadata">Object containing metadata for Matter</param>
        private void SetFieldValues(ClientContext clientContext, IList <ContentType> contentTypeCollection, List matterList,
                                    MatterMetadata matterMetadata)
        {
            FieldCollection fields = GetContentType(clientContext, contentTypeCollection, matterList);

            if (null != fields)
            {
                matterMetadata = GetWSSId(clientContext, matterMetadata, fields);
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).DefaultValue  = matterMetadata.Client.Id;
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).ReadOnlyField = true;
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).SetShowInDisplayForm(true);
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).Update();
                if (configuration.GetSection("General")["IsBackwardCompatible"].ToString() == "false")
                {
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).ReadOnlyField = true;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).SetShowInDisplayForm(true);
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).DefaultValue = matterMetadata.Client.Name;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).Update();
                }
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).DefaultValue  = matterMetadata.Matter.Id;
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).ReadOnlyField = true;
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).SetShowInDisplayForm(true);
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).Update();
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).DefaultValue  = matterMetadata.Matter.Name;
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).ReadOnlyField = true;
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).SetShowInDisplayForm(true);
                fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).Update();

                int levels = taxonomySettings.Levels;
                //For the number of levels that are configured, get the configured column name and
                //update the wssid, termname and id for the managed field
                for (int i = 1; i <= levels; i++)
                {
                    string columnName = configuration.GetSection("ContentTypes").GetSection("ManagedColumns")["ColumnName" + i];
                    fields.GetByInternalNameOrTitle(columnName).SetShowInDisplayForm(true);
                    ManagedColumn managedColumn = matterMetadata.ManagedColumnTerms[columnName];
                    fields.GetByInternalNameOrTitle(columnName).DefaultValue =
                        string.Format(CultureInfo.InvariantCulture, ServiceConstants.MetadataDefaultValue,
                                      managedColumn.WssId,
                                      managedColumn.TermName,
                                      managedColumn.Id);
                    fields.GetByInternalNameOrTitle(columnName).Update();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Assigns field values for specified content types to the specified matter (document library).
        /// </summary>
        /// <param name="clientContext">SP client context</param>
        /// <param name="contentTypeCollection">Collection of content types</param>
        /// <param name="matterList">List containing matters</param>
        /// <param name="matterMetadata">Object containing metadata for Matter</param>
        private void SetFieldValues(ClientContext clientContext, IList <ContentType> contentTypeCollection, List matterList,
                                    MatterMetadata matterMetadata)
        {
            try
            {
                FieldCollection fields = GetContentType(clientContext, contentTypeCollection, matterList);
                if (null != fields)
                {
                    matterMetadata = GetWSSId(clientContext, matterMetadata, fields);
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).DefaultValue = matterMetadata.Client.Id;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).SetShowInDisplayForm(true);
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).ReadOnlyField = true;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientId).Update();
                    if (configuration.GetSection("General")["IsBackwardCompatible"].ToString().ToLower() == "false")
                    {
                        fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).SetShowInDisplayForm(true);
                        fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).DefaultValue  = matterMetadata.Client.Name;
                        fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).ReadOnlyField = true;
                        fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnClientName).Update();
                    }
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).DefaultValue = matterMetadata.Matter.Id;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).SetShowInDisplayForm(true);
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).ReadOnlyField = true;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterId).Update();
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).DefaultValue  = matterMetadata.Matter.Name;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).ReadOnlyField = true;
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).SetShowInDisplayForm(true);
                    fields.GetByInternalNameOrTitle(contentTypesConfig.ContentTypeColumnMatterName).Update();

                    int levels = taxonomySettings.Levels;
                    //For the number of levels that are configured, get the configured column name and
                    //update the wssid, termname and id for the managed field
                    for (int i = 1; i <= levels; i++)
                    {
                        string columnName = configuration.GetSection("ContentTypes").GetSection("ManagedColumns")["ColumnName" + i];
                        fields.GetByInternalNameOrTitle(columnName).SetShowInDisplayForm(true);
                        ManagedColumn managedColumn = matterMetadata.ManagedColumnTerms[columnName];
                        fields.GetByInternalNameOrTitle(columnName).DefaultValue =
                            string.Format(CultureInfo.InvariantCulture, ServiceConstants.MetadataDefaultValue,
                                          managedColumn.WssId,
                                          managedColumn.TermName,
                                          managedColumn.Id);
                        fields.GetByInternalNameOrTitle(columnName).Update();
                    }
                    //To set the values of new content type site columns and update it in sharepoint .
                    //Update the values of site columns of Additional content type at Matter level
                    MatterExtraProperties matterExtraProperties = matterMetadata.MatterExtraProperties;;

                    foreach (var extraField in matterExtraProperties.Fields)
                    {
                        if (extraField.Type == "Text")
                        {
                            fields.GetByInternalNameOrTitle(extraField.FieldName).DefaultValue = extraField.FieldValue;
                            fields.GetByInternalNameOrTitle(extraField.FieldName).SetShowInDisplayForm(true);
                            fields.GetByInternalNameOrTitle(extraField.FieldName).Update();
                        }
                        else
                        {
                            fields.GetByInternalNameOrTitle(extraField.FieldName).DefaultValue = extraField.FieldValue;
                            fields.GetByInternalNameOrTitle(extraField.FieldName).Update();
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name,
                                      MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }
        }