Beispiel #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="web"></param>
    /// <param name="contentTypeName"></param>
    public static void RemoveContentType(this SPWeb web, string contentTypeName)
    {
        try
        {
            web.AllowUnsafeUpdates = true;

            SPContentTypeCollection contentTypes = web.ContentTypes;

            contentTypes.Delete(contentTypes[contentTypeName].Id);
        }
        catch (Exception ex)
        {
            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("CORE:HELPERS", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, String.Format("Exception happened in Helpers:RemoveContentType. MESSAGE: {0}. EXCEPTION TRACE: {1} ", ex.Message, ex.StackTrace), ex.StackTrace);
        }
        finally
        {
            web.AllowUnsafeUpdates = true;
        }
    }
        public void Delete(object contentTypeId)
        {
            if (contentTypeId == Undefined.Value)
            {
                throw new JavaScriptException(this.Engine, "Error", "A Content Type Id must be provided as the first argument.");
            }

            SPContentTypeId spContentTypeId;

            if (contentTypeId is SPContentTypeIdInstance)
            {
                spContentTypeId = (contentTypeId as SPContentTypeIdInstance).ContentTypeId;
            }
            else
            {
                spContentTypeId = new SPContentTypeId(TypeConverter.ToString(contentTypeId));
            }

            m_contentTypeCollection.Delete(spContentTypeId);
        }