forked from jcroav/SPHelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.cs
46 lines (43 loc) · 1.9 KB
/
Utility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public static class Utility
{
/// <summary>
///
/// </summary>
/// <param name="web"></param>
/// <param name="group"></param>
public static void RemoveContentTypesByGroup(this SPWeb web, string group)
{
try
{
List<SPContentType> contentTypes = web.AvailableContentTypes.Cast<SPContentType>().Where(p => p.Group == group).ToList();
foreach(SPContentType contentType in contentTypes)
{
web.RemoveContentType(contentType.Name);
}
}
catch (Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("CORE:UTILITY", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, String.Format("Exception happened in Helpers:RemoveContentTypesByGroup. MESSAGE: {0}. EXCEPTION TRACE: {1} ", ex.Message, ex.StackTrace), ex.StackTrace);
}
}
/// <summary>
///
/// </summary>
/// <param name="web"></param>
/// <param name="group"></param>
public static void RemoveSiteColumnsByGroup(this SPWeb web, string group)
{
try
{
List<SPField> fields = web.AvailableFields.Cast<SPField>().Where(f => f.Group == group).ToList();
foreach (SPField field in fields)
{
web.RemoveSiteColumn(field.Title);
}
}
catch (Exception ex)
{
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("CORE:UTILITY", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, String.Format("Exception happened in Helpers:RemoveSiteColumnsByGroup. MESSAGE: {0}. EXCEPTION TRACE: {1} ", ex.Message, ex.StackTrace), ex.StackTrace);
}
}
}