In the code sample below, activating the feature will remove all possible web templates with the exception of the standard Document Workspace template from the display list. Deactivating the feature will allow the list of options to return to its normal mode of displaying all web templates:
public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { SPWeb web = properties.Feature.Parent as SPWeb; // Hide all available web templates with the exception of the Document Center web template SPWebTemplateCollection currentTemplates = web.GetAvailableWebTemplates(1033); CollectionnewTemplates = new Collection (); foreach (SPWebTemplate currentTemplate in currentTemplates) { if (currentTemplate.Title.Trim() == "Document Workspace") { newTemplates.Add(currentTemplate); } } web.SetAvailableWebTemplates(newTemplates, 1033); web.Update(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { try { SPWeb web = properties.Feature.Parent as SPWeb; // Show all available web templates web.AllowAllWebTemplates(); web.Update(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.