/// <summary> /// Checks to see if the given master page exists in the site collections Master Page library /// </summary> /// <param name="properties"></param> /// <param name="_masterpage">Name of the master page to chech against</param> /// <returns></returns> private Boolean CheckIfMasterPageExist(SPWebEventProperties properties, String _masterpage) { Boolean _bln = false; try { using (SPSite site = new SPSite(properties.SiteId)) { using (SPWeb web = site.OpenWeb()) { SPList myList = web.Lists["Master Page Gallery"]; SPQuery oQuery = new SPQuery(); oQuery.Query = string.Format("<Where><Contains><FieldRef Name=\"FileLeafRef\" /><Value Type=\"File\">.master</Value></Contains></Where><OrderBy><FieldRef Name=\"FileLeafRef\" /></OrderBy>"); SPListItemCollection colListItems = myList.GetItems(oQuery); foreach (SPListItem currentItem in colListItems) { if (currentItem.Name.Trim().ToLower() == _masterpage.Trim().ToLower()) { _bln = true; break; } } } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - CheckIfMasterPageExist: " + ex.Message + " " + ex.StackTrace); } return(_bln); }
public override void WebProvisioned(SPWebEventProperties properties) { //this.CreateWorkItem(properties); this.SetAvailableSubWebs(properties); ////Add code for event WebProvisioned in SymanticWebHandler }
private void MUIProcess(SPWebEventProperties properties) { try { using (SPSite site = new SPSite(properties.Web.Site.ID)) { using (SPWeb web = site.AllWebs[properties.WebId]) { web.IsMultilingual = true; // Add support for any installed language currently not supported. SPLanguageCollection installed = SPRegionalSettings.GlobalInstalledLanguages; IEnumerable <CultureInfo> cultures = web.SupportedUICultures; foreach (SPLanguage language in installed) { CultureInfo culture = new CultureInfo(language.LCID); if (!cultures.Contains(culture)) { web.AddSupportedUICulture(culture); } } web.Update(); } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - MUIProcess: " + ex.Message + " " + ex.StackTrace); } }
/// <summary> /// A site was provisioned /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { base.WebProvisioned(properties); SPWeb currentWeb = properties.Web; if (currentWeb != null) { string webAppRelativePath = currentWeb.ServerRelativeUrl; if (!webAppRelativePath.EndsWith("/")) { webAppRelativePath += "/"; } SPFile file = currentWeb.GetFile("/_catalogs/masterpage/_custom.master"); if (file.Exists) { if (file.CustomizedPageStatus == SPCustomizedPageStatus.Customized) { file.RevertContentStream(); } } Uri masterUri = new Uri(currentWeb.Url + "/_catalogs/masterpage/_custom.master"); currentWeb.MasterUrl = masterUri.AbsolutePath; // Very Important for Publishing Site and not required for other templates currentWeb.CustomMasterUrl = masterUri.AbsolutePath; currentWeb.UIVersion = 4; currentWeb.Update(); } }
/// <summary> /// Log web event properties /// </summary> /// <param name="properties"></param> private void LogWebEventProperties(SPWebEventProperties properties) { // Specify log list name string listName = "WebEventLogger"; // Create string builder object StringBuilder sb = new StringBuilder(); // Add properties the don't throw exceptions sb.AppendFormat("Cancel: {0}\n", properties.Cancel); sb.AppendFormat("ErrorMessage: {0}\n", properties.ErrorMessage); sb.AppendFormat("EventType: {0}\n", properties.EventType); sb.AppendFormat("FullUrl: {0}\n", properties.FullUrl); sb.AppendFormat("NewServerRelativeUrl: {0}\n", properties.NewServerRelativeUrl); sb.AppendFormat("ParentWebId: {0}\n", properties.ParentWebId); sb.AppendFormat("ReceiverData: {0}\n", properties.ReceiverData); sb.AppendFormat("RedirectUrl: {0}\n", properties.RedirectUrl); sb.AppendFormat("ServerRelativeUrl: {0}\n", properties.ServerRelativeUrl); sb.AppendFormat("SiteId: {0}\n", properties.SiteId); sb.AppendFormat("Status: {0}\n", properties.Status); sb.AppendFormat("UserDisplayName: {0}\n", properties.UserDisplayName); sb.AppendFormat("UserLoginName: {0}\n", properties.UserLoginName); sb.AppendFormat("WebId: {0}\n", properties.WebId); sb.AppendFormat("Web: {0}\n", properties.Web); // Log the event to the list this.EventFiringEnabled = false; Common.LogEvent(properties.Web, listName, properties.EventType, sb.ToString()); this.EventFiringEnabled = true; }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { base.WebProvisioned(properties); SPSite siteCollection = properties.Web.Site; SPWeb subSite = properties.Web; if (!subSite.WebTemplate.Contains("APP")) { Guid sitePublishingGuid = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa"); Guid webPublishingGuid = new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"); EnsureSiteFeatureActivated(sitePublishingGuid, siteCollection); EnsureWebFeatureActivated(webPublishingGuid, siteCollection, subSite); var pubWeb = PublishingWeb.GetPublishingWeb(subSite); var webNavigationSettings = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(subSite); webNavigationSettings.GlobalNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.InheritFromParentWeb; webNavigationSettings.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider; webNavigationSettings.Update(); pubWeb.Update(); subSite.MasterUrl = siteCollection.RootWeb.MasterUrl; subSite.CustomMasterUrl = siteCollection.RootWeb.CustomMasterUrl; subSite.SiteLogoUrl = siteCollection.RootWeb.SiteLogoUrl; subSite.Update(); } }
private void CreateWorkItem(SPWebEventProperties properties, string fullClass, string fullAssembly) { Guid siteId = properties.SiteId; Guid webId = properties.WebId; string _modulename = fullClass; string _assembly = fullAssembly; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerModuleWorkItem.WorkItemTypeId, webId, siteId, 1, true, Guid.Empty, Guid.Empty, site.SystemAccount.ID, null, _modulename + ";" + _assembly, Guid.Empty ); } }); }
/// <summary> /// A site is being provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { properties.Web.Title += String.Format(" [Created By: {0}]", properties.UserDisplayName); properties.Web.AllowUnsafeUpdates = true; properties.Web.Update(); base.WebAdding(properties); }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { SPDiagnosticsService diagSvc = SPDiagnosticsService.Local; SPSecurity.RunWithElevatedPrivileges(delegate() { try { base.WebProvisioned(properties); var rootWeb = properties.Web.Site.RootWeb; var currentWeb = properties.Web; var siteCollection = currentWeb.Site; using (currentWeb) { var webAppRelativePath = BrandingHelper.WebAppPath(currentWeb, siteCollection); BrandingHelper.InheritTopSiteBranding(currentWeb, rootWeb, siteCollection, webAppRelativePath); } } catch (Exception ex) { diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Error Info", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, "Houston, we have a problem in WebProvisioned event: {0}---{1}", ex.InnerException, ex.StackTrace); } }); }
/// <summary> /// Fires when a new web is created and changes the site's main and custom master page /// </summary> /// <param name="properties">The context</param> public override void WebProvisioned(SPWebEventProperties properties) { SPWeb site = properties.Web; SPWeb rootSite = site.Site.RootWeb; site.MasterUrl = rootSite.MasterUrl; site.CustomMasterUrl = rootSite.CustomMasterUrl; site.Update(); }
public override void WebDeleting(SPWebEventProperties properties) { using (var site = new SPSite(properties.SiteId)) { string backupLocation = @"E:\Labfiles\Starter\Backup.backup"; site.WebApplication.Sites.Backup(site.Url, backupLocation, true); } }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { SPWeb childSite = properties.Web; SPWeb topSite = childSite.Site.RootWeb; childSite.MasterUrl = topSite.MasterUrl; childSite.CustomMasterUrl = topSite.CustomMasterUrl; childSite.Update(); }
/// <summary> /// /// </summary> /// <param name="properties"></param> private void DefaultNavigation(SPWebEventProperties properties) { int level; try { using (SPSite site = new SPSite(properties.Web.Site.ID)) { using (SPWeb web = site.AllWebs[properties.WebId]) { PublishingSite pubsite = new PublishingSite(site); PublishingWeb pubWeb = this.GetPublishingSiteFromWeb(web); level = web.ServerRelativeUrl.Split('/').Length - 1; switch (level) { case 0: //Global Navigation Settings pubWeb.Navigation.GlobalIncludeSubSites = true; pubWeb.Navigation.GlobalIncludePages = false; //Current Navigation Settings pubWeb.Navigation.CurrentIncludeSubSites = true; pubWeb.Navigation.CurrentIncludePages = false; web.Update(); break; case 1: //Global Navigation Settings pubWeb.Navigation.InheritGlobal = true; pubWeb.Navigation.GlobalIncludeSubSites = true; pubWeb.Navigation.GlobalIncludePages = false; //Current Navigation Settings pubWeb.Navigation.ShowSiblings = true; pubWeb.Navigation.CurrentIncludeSubSites = true; pubWeb.Navigation.CurrentIncludePages = false; pubWeb.Update(); break; default: //Global Navigation Settings pubWeb.Navigation.InheritGlobal = true; pubWeb.Navigation.GlobalIncludeSubSites = true; pubWeb.Navigation.GlobalIncludePages = false; //Current Navigation Settings pubWeb.Navigation.InheritCurrent = true; pubWeb.Navigation.CurrentIncludeSubSites = true; pubWeb.Navigation.CurrentIncludePages = false; pubWeb.Update(); break; } } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - DefaultNavigation: " + ex.Message + " " + ex.StackTrace); } }
public override void WebDeleted(SPWebEventProperties properties) { try { if (properties.Web.WebTemplate.ToLower() == "websitesearch") { if (properties.Web.IsRootWeb) { List <DropDownModesEx> dropDownModesThatCanUseResultPage = new List <DropDownModesEx> { DropDownModesEx.HideScopeDD, DropDownModesEx.HideScopeDD_DefaultContextual, DropDownModesEx.ShowDD, DropDownModesEx.ShowDD_DefaultContextual, DropDownModesEx.ShowDD_DefaultURL, DropDownModesEx.ShowDD_NoContextual, DropDownModesEx.ShowDD_NoContextual_DefaultURL }; properties.Web.AllowUnsafeUpdates = true; //SRCH_ENH_FTR_URL if (properties.Web.AllProperties.Contains("SRCH_ENH_FTR_URL")) { properties.Web.AllProperties["SRCH_ENH_FTR_URL"] = "/_layouts/searchresults.aspx"; } else { properties.Web.AllProperties.Add("SRCH_ENH_FTR_URL", "/_layouts/searchresults.aspx"); } //SRCH_TRAGET_RESULTS_PAGE if (properties.Web.AllProperties.Contains("SRCH_TRAGET_RESULTS_PAGE")) { properties.Web.AllProperties["SRCH_TRAGET_RESULTS_PAGE"] = "/_layouts/searchresults.aspx"; } else { properties.Web.AllProperties.Add("SRCH_TRAGET_RESULTS_PAGE", "/_layouts/searchresults.aspx"); } /* * //SRCH_SITE_DROPDOWN_MODE * if (properties.Web.AllProperties.Contains("SRCH_SITE_DROPDOWN_MODE")) * { * properties.Web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = ""; * } * else * { * properties.Web.AllProperties.Add("SRCH_SITE_DROPDOWN_MODE", ""); * } */ properties.Web.Update(); properties.Web.AllowUnsafeUpdates = false; } } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } }
public override void WebDeleting(SPWebEventProperties properties) { ////Add code for event WebDeleting in WebSiteSearchHandler /* * properties.Cancel = true; * properties.ErrorMessage = "Deleting is not supported."; */ }
public override void WebProvisioned(SPWebEventProperties properties) { var web = properties.Web; var rootWeb = web.Site.RootWeb; _masterPageUrl = SPUrlUtility.CombineUrl(rootWeb.ServerRelativeUrl, MasterPagePath + _masterPageUrl); _searchMasterPageUrl = SPUrlUtility.CombineUrl(rootWeb.ServerRelativeUrl, MasterPagePath + _searchMasterPageUrl); web.MasterUrl = _masterPageUrl; web.CustomMasterUrl = _searchWebTemplates.Contains(web.WebTemplate) ? _searchMasterPageUrl : _masterPageUrl; web.Update(); }
/// <summary> /// A site is being deleted /// </summary> public override void WebDeleting(SPWebEventProperties properties) { if (properties.Web.WebTemplate.ToLower() == "websiteroot") { /* * properties.Cancel = true; * properties.ErrorMessage = "Deleting is not supported."; * //base.WebDeleting(properties); */ } }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { SPWeb childSite = properties.Web; SPWeb topSite = childSite.Site.RootWeb; childSite.MasterUrl = topSite.MasterUrl; childSite.CustomMasterUrl = topSite.CustomMasterUrl; childSite.AlternateCssUrl = topSite.AlternateCssUrl; childSite.SiteLogoUrl = topSite.SiteLogoUrl; childSite.Update(); }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { SPWeb childSite = properties.Web; SPWeb topSite = childSite.Site.RootWeb; childSite.MasterUrl = topSite.MasterUrl; childSite.CustomMasterUrl = topSite.MasterUrl; childSite.Navigation.GlobalNodes.Navigation.UseShared = true; childSite.Update(); }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { using (SPWeb web = properties.Web) { string webId = web.ServerRelativeUrl.Substring(web.ServerRelativeUrl.LastIndexOf("/") + 1); SPListItem parentListItem = web.ParentWeb.Lists["Matters"].GetItemById(int.Parse(webId)); //See if the current site has a "Matter Summary" list SPList matterSummaryList = web.Lists.TryGetList("Matter Summary"); if (matterSummaryList != null && parentListItem != null) { //Only process items where the parent content type was "matter". Linked matters are handled through the synchronization process if (parentListItem["Content Type"].ToString() == "Matter") { SPListItem newSummaryItem = matterSummaryList.AddItem(); newSummaryItem["Matter Name"] = parentListItem["Matter Name"]; newSummaryItem["Account Name"] = parentListItem["Account Name"]; newSummaryItem["Litigation Manager"] = parentListItem["Litigation Manager"]; newSummaryItem["Matter Status"] = parentListItem["Matter Status"]; newSummaryItem["Case Caption"] = parentListItem["Case Caption"]; newSummaryItem["Docket Number"] = parentListItem["Docket Number"]; UpdateMMField(newSummaryItem, "Litigation Type", parentListItem["Litigation Type_0"].ToString(), "Litigation Type_0"); UpdateMMField(newSummaryItem, "State Filed", parentListItem["State Filed_0"].ToString(), "State Filed_0"); UpdateMMField(newSummaryItem, "Venue", parentListItem["Venue_0"].ToString(), "Venue_0"); UpdateMMField(newSummaryItem, "Affiliate", parentListItem["Affiliate_0"].ToString(), "Affiliate_0"); UpdateMMField(newSummaryItem, "Work/Matter Type", parentListItem["Claim Type_0"].ToString(), "Claim Type_0"); newSummaryItem["Claim Group ID"] = parentListItem["Claim Group ID"]; newSummaryItem["External Firm Name"] = parentListItem["External Firm Name"]; newSummaryItem.Update(); return; } } //See if the current site has a "Project Summary" list SPList projectSummaryList = web.Lists.TryGetList("Project Summary"); if (projectSummaryList != null) { //Add a project summary item to the list if (parentListItem["Content Type"].ToString() == "Project") { SPListItem newSummaryItem = projectSummaryList.AddItem(); newSummaryItem["Project Name"] = parentListItem["Project Name"]; newSummaryItem["Project Description"] = parentListItem["Project Description"]; newSummaryItem["Project Lead"] = parentListItem["Project Lead"]; newSummaryItem["Project Status"] = parentListItem["Project Status"]; newSummaryItem["Project Site"] = parentListItem["Project Site"]; newSummaryItem.Update(); return; } } } }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { //base.WebProvisioned(properties); SPWeb web = properties.Web; SPWeb rootWeb = web.Site.RootWeb; web.MasterUrl = rootWeb.MasterUrl; //web.CustomMasterUrl = rootWeb.CustomMasterUrl; //web.AlternateCssUrl = rootWeb.AlternateCssUrl; //web.SiteLogoUrl = rootWeb.SiteLogoUrl; web.Update(); }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { base.WebProvisioned(properties); SPWeb currentWeb = properties.Web; string masterURL = currentWeb.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/MasterPage/CustomMaster.master"; string customMasterURL = currentWeb.Site.RootWeb.ServerRelativeUrl + "/_catalogs/masterpage/MasterPage/CustomMaster.master"; currentWeb.MasterUrl = masterURL; currentWeb.CustomMasterUrl = customMasterURL; currentWeb.Update(); //InitializeWebAppProperties(currentWeb); //TaxonomySession taxonomySession = new TaxonomySession(currentWeb.Site, updateCache: true); ////Use the first Termstore object to see if Taxonomy Service is offline or missing. //if (taxonomySession.TermStores.Count == 0) // throw new InvalidOperationException("The Taxonomy Service is offline or missing."); //string globalTermSetID = "Empty"; //string localTermSetID = "Empty"; ////Get the values from the property bags. //globalTermSetID = Convert.ToString(currentWeb.Site.RootWeb.AllProperties[globalTermSetIDPropertyKey]); //localTermSetID = Convert.ToString(currentWeb.Site.RootWeb.AllProperties[localTermSetIDPropertyKey]); //TermStore termStore = taxonomySession.TermStores[termStoreName]; //TermSet globalTermSet = termStore.GetTermSet(new Guid(globalTermSetID)); //TermSet localTermSet = termStore.GetTermSet(new Guid(localTermSetID)); //Group termSetGroup = termStore.GetSiteCollectionGroup(currentWeb.Site); //WebNavigationSettings webNavigationSettings = new WebNavigationSettings(currentWeb); //webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.TaxonomyProvider; //webNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.TaxonomyProvider; //webNavigationSettings.GlobalNavigation.TermStoreId = termStore.Id; //webNavigationSettings.GlobalNavigation.TermSetId = new Guid(globalTermSetID); //webNavigationSettings.CurrentNavigation.TermStoreId = termStore.Id; //webNavigationSettings.CurrentNavigation.TermSetId = new Guid(localTermSetID); //webNavigationSettings.AddNewPagesToNavigation = false; //webNavigationSettings.CreateFriendlyUrlsForNewPages = true; //webNavigationSettings.Update(); //currentWeb.Update(); }
/// <summary> /// A site is being deleted. /// </summary> public override void WebDeleting(SPWebEventProperties properties) { try { if (properties.Web.Lists["Data"] != null) { properties.Cancel = true; } } catch { //throw new SPException("Cannot delete the site because it has user data in it"); } base.WebDeleting(properties); }
// Public Methods (2) /// <summary> /// A site is being deleted. /// </summary> public override void WebDeleting(SPWebEventProperties properties) { try { SocialEngine.Current.ProcessActivity(ObjectKind.Workspace, ActivityKind.Deleted, new Dictionary <string, object> { { "Id", properties.WebId }, { "Title", properties.Web.Title }, { "URL", properties.ServerRelativeUrl }, { "UserId", properties.Web.CurrentUser.ID }, { "ActivityTime", DateTime.Now } }, properties.Web); } catch { } }
public override void WebProvisioned(SPWebEventProperties properties) { try { if (properties.Web.WebTemplate.ToLower() == "websiteabout") { properties.Web.AllowUnsafeUpdates = true; SPFolder rootFolder = properties.Web.RootFolder; //SPFile file = properties.Web.GetFile("Pages/Default.aspx"); rootFolder.WelcomePage = "Pages/default.aspx"; rootFolder.Update(); properties.Web.Update(); properties.Web.AllowUnsafeUpdates = false; } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } SPUtility.ValidateFormDigest(); try { SPList page = properties.Web.Lists["Pages"]; //page.DraftVersionVisibility = DraftVisibilityType.Author | DraftVisibilityType.Approver; page.EnableVersioning = true; page.EnableMinorVersions = true; page.EnableThrottling = true; page.Update(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } if (properties.Web.WebTemplate.ToLower() == "websiteabout") { CreateWorkItem(properties, "/Pages/default.aspx", ""); CreateWorkItem(properties, "/Pages/People.aspx", "/People"); CreateWorkItem(properties, "/Pages/About.aspx", "/About"); CreateWorkItem(properties, "/Pages/Legal.aspx", "/Legal"); CreateWorkItem(properties, "/Pages/History.aspx", "/History"); } }
private void SetAvailableSubWebs(SPWebEventProperties properties) { SPWeb web = properties.Web; if (!web.AllProperties.ContainsKey("__WebTemplates")) { web.AllProperties.Add("__WebTemplates", ""); } web.AllowAllWebTemplates(); web.Update(); SPWebTemplateCollection existingLanguageNeutralTemplatesCollection = web.GetAvailableCrossLanguageWebTemplates(); SPWebTemplateCollection existingLanguageSpecificTemplatesCollection = web.GetAvailableWebTemplates(web.Language); Collection <SPWebTemplate> newLanguageNeutralTemplatesCollection = new Collection <SPWebTemplate>(); Collection <SPWebTemplate> newLanguageSpecificTemplatesCollection = new Collection <SPWebTemplate>(); foreach (SPWebTemplate existingTemplate in existingLanguageNeutralTemplatesCollection) { if (existingTemplate.DisplayCategory.Contains("WebSite")) { newLanguageNeutralTemplatesCollection.Add(existingTemplate); } } foreach (SPWebTemplate existingTemplate in existingLanguageSpecificTemplatesCollection) { if (existingTemplate.DisplayCategory.Contains("WebSite")) { newLanguageSpecificTemplatesCollection.Add(existingTemplate); } } if (newLanguageNeutralTemplatesCollection.Count != 0) { web.SetAvailableCrossLanguageWebTemplates(newLanguageNeutralTemplatesCollection); } if (newLanguageSpecificTemplatesCollection.Count != 0) { web.SetAvailableWebTemplates(newLanguageSpecificTemplatesCollection, web.Language); } web.Update(); }
/// <summary> /// A site is being deleted. /// </summary> public override void SiteDeleting(SPWebEventProperties properties) { try { SPWeb web = properties.Web as SPWeb; SPPropertyBag currentBag = web.Properties; if (currentBag.ContainsKey(ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive) && currentBag[ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive] != null) { string siteId = currentBag[ConfigValues.PiwikPro_PropertyBag_SiteId]; string siteTitle = string.Empty; PropertyBagOperations pbo = new PropertyBagOperations(); SPSecurity.RunWithElevatedPrivileges(delegate() { // using (SPWeb web = new SPSite(ConfigValues.PiwikPro_PiwikAdminSiteUrl).OpenWeb()) // using (SPWeb webz = new SPSite(pbo.GetPropertyValueFromListByKey("piwik_adminsiteurl")).OpenWeb()) //{ ClientContext context = new ClientContext(pbo.GetPropertyValueFromListByKey(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_AdminSiteUrl))); Configuration cfg = new Configuration(); ListProcessor sdlo = new ListProcessor(context, cfg, new SPLogger()); ListItem item = sdlo.CheckIfElementIsAlreadyOnList(context.Web.ServerRelativeUrl); if (item != null) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Deleted; siteTitle = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]); item.Update(); } //} PiwikPROServiceOperations pso = new PiwikPROServiceOperations(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientID), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientSecret), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_OldApiToken), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ServiceUrl), new SPLogger()); pso.ChangeNameSiteInPiwik("Deleted - " + Convert.ToString(siteTitle), siteId); }); } } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, "Piwik WebDeleting", ex.Message); } base.SiteDeleting(properties); }
/// <summary> /// A site was deleted. /// </summary> public override void WebDeleted(SPWebEventProperties properties) { base.WebDeleted(properties); //TODO Добавить обработку события удаления вебы using (SPWeb web = properties.Web.Site.RootWeb) { SPListItemCollection delitingSitesRecoeds = Queries.GetWebRegistrySiteByURL(web, properties.FullUrl); Logger.WriteLog(Logger.Category.Information, "DetectionSubSiteEventReceiver", "Event WebDeleted. Strarting removing sites from list. Finded " + delitingSitesRecoeds.Count.ToString() + " items"); if (delitingSitesRecoeds != null && delitingSitesRecoeds.Count > 0) { foreach (SPListItem item in delitingSitesRecoeds) { using (EventReceiverScope scope = new EventReceiverScope(false)) { item.Delete(); } } } } }
/// <summary> /// A site was provisioned. /// </summary> /// <param name="properties">Event receiver properties</param> public override void WebProvisioned(SPWebEventProperties properties) { ////Update Master Page after new subsite was created SPSecurity.RunWithElevatedPrivileges(delegate { var web = properties.Web; if (!web.Exists) { return; } web.AllowUnsafeUpdates = true; var masterPagePath = $"{web.Site.RootWeb.ServerRelativeUrl}_catalogs/masterpage/stada.master"; web.MasterUrl = masterPagePath; web.CustomMasterUrl = masterPagePath; // web.Update(); //SPHelper.ActiveInstalledLanguage(web); web.AllowUnsafeUpdates = false; }); }
private void DefaultMasterPageProcess(SPWebEventProperties properties) { try { using (SPSite site = new SPSite(properties.Web.Site.ID)) { using (SPWeb web = site.AllWebs[properties.WebId]) { if (CheckIfMasterPageExist(properties, defaultMasterPage)) { web.CustomMasterUrl = "/_catalogs/masterpage/" + defaultMasterPage; web.Update(); } } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - DefaultMasterPageProcess: " + ex.Message + " " + ex.StackTrace); } }
public override void WebProvisioned(SPWebEventProperties properties) { base.WebProvisioned(properties); using (SPSite site = new SPSite(properties.Web.Site.ID)) { using (SPWeb web = site.AllWebs[properties.WebId]) { if (PublishingWeb.IsPublishingWeb(web)) { SPSecurity.RunWithElevatedPrivileges(delegate() { DefaultMasterPageProcess(properties); DefaultPageLayoutProcess(properties); MUIProcess(properties); DefaultNavigation(properties); CreateFooterList(properties); }); } } } }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { try { SocialEngine.Current.ProcessActivity(ObjectKind.Workspace, ActivityKind.Created, new Dictionary <string, object> { { "Id", properties.WebId }, { "Title", properties.Web.Title }, { "URL", properties.ServerRelativeUrl }, { "UserId", properties.Web.CurrentUser.ID }, { "ActivityTime", DateTime.Now } }, properties.Web); } catch { } try { CoreFunctions.ScheduleReportingRefreshJob(properties.Web); } catch { } }
public override void WebProvisioned(SPWebEventProperties properties) { try { if (properties.Web.WebTemplate.ToLower() == "clubcloudafhangen") { properties.Web.AllowUnsafeUpdates = true; properties.Web.AnonymousState = SPWeb.WebAnonymousState.Enabled; SPFolder rootFolder = properties.Web.RootFolder; rootFolder.WelcomePage = "index.html"; rootFolder.Update(); properties.Web.Update(); properties.Web.AllowUnsafeUpdates = false; } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } SPUtility.ValidateFormDigest(); }
/// <summary> /// A site is being provisioned /// </summary> public override void WebAdding(SPWebEventProperties properties) { base.WebAdding(properties); using (SPWeb web = properties.Web) { SPList webRegistryList = web.Lists.TryGetList(Constants.WebRegistry.ListTitle); if (webRegistryList != null) { SPListItem webRegistryItem = webRegistryList.Items.Add(); webRegistryItem[Constants.WebRegistry.SiteRelativeUrl] = SPUrlUtility.CombineUrl(properties.FullUrl, properties.NewServerRelativeUrl); webRegistryItem[Constants.WebRegistry.Template] = properties.Web.ID; webRegistryItem[Constants.WebRegistry.CreatedDate] = DateTime.Now; using (EventReceiverScope scope = new EventReceiverScope(false)) { webRegistryItem.Update(); } Logger.WriteLog(Logger.Category.Information, "DetectionSubSiteEventReceiver", "Event WebAdding. Added new Web Registry element in list"); } else { Logger.WriteLog(Logger.Category.High, "DetectionSubSiteEventReceiver", "Event WebAdding. WebRegistry List is null"); } } }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { base.WebProvisioned(properties); try { SPEventReceiverDefinition pageAddedEvt = properties.Web.Site.EventReceivers .OfType <SPEventReceiverDefinition>() .FirstOrDefault(evt => evt.Name == "EVT_PageCreatedItemAdded"); if (pageAddedEvt != null) { foreach (SPList list in properties.Web.Lists.OfType <SPList>().Where(l => !l.Hidden && l.BaseType == SPBaseType.DocumentLibrary)) { SPEventReceiverDefinition newEvt = list.EventReceivers.Add(pageAddedEvt.Id); newEvt.Update(); list.Update(); } } } catch { } }
private void CreateFooterList(SPWebEventProperties properties) { int level; try { using (SPSite site = new SPSite(properties.Web.Site.ID)) { using (SPWeb web = site.AllWebs[properties.WebId]) { level = web.ServerRelativeUrl.Split('/').Length - 1; if (level == 1) { //Check if list already exists, if not, create one. footerList = web.Lists.TryGetList(footerListName); if (footerList == null) web.Lists.Add(footerListName, "This SharePoint list is used for the WET 4 Footer", listtype); SPList list = web.Lists[footerListName]; list.EnableFolderCreation = true; // create columns //assume that column "Title" is already created list.Fields.Add("NavURL", SPFieldType.Text, false); list.Fields.Add("RowOrder", SPFieldType.Number, true); // make new column visible in default view SPView view = list.DefaultView; view.ViewFields.Add("Type"); view.ViewFields.Add("NavURL"); view.ViewFields.Add("RowOrder"); view.Update(); #region Create About Us //Create Folders SPListItem folderItem = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder); folderItem["Title"] = "About Us"; folderItem.Update(); //create a listitem object to add item in the foler SPListItem listItem = list.Items.Add(folderItem.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem["Title"] = "About Us"; listItem["NavURL"] = "/eng/Pages/about.aspx"; listItem["RowOrder"] = 1; listItem.Update(); SPListItem listItem2 = list.Items.Add(folderItem.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem2["Title"] = "Our Mandate"; listItem2["NavURL"] = "/eng/Pages/mandate.aspx"; listItem2["RowOrder"] = 2; listItem2.Update(); SPListItem listItem3 = list.Items.Add(folderItem.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem3["Title"] = "Our Minister"; listItem3["NavURL"] = "/eng/Pages/minister.aspx"; listItem3["RowOrder"] = 3; listItem3.Update(); list.Update(); #endregion #region Create Contact Us SPListItem folderItem2 = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder); folderItem2["Title"] = "Contact Us"; folderItem2.Update(); SPListItem listItem4 = list.Items.Add(folderItem2.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem4["Title"] = "Contact Us"; listItem4["NavURL"] = "/eng/Pages/contact.aspx"; listItem4["RowOrder"] = 1; listItem4.Update(); SPListItem listItem5 = list.Items.Add(folderItem2.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem5["Title"] = "Phone numbers"; listItem5["NavURL"] = "/eng/Pages/phone.aspx"; listItem5["RowOrder"] = 2; listItem5.Update(); SPListItem listItem6 = list.Items.Add(folderItem2.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem6["Title"] = "Office locations"; listItem6["NavURL"] = "/eng/Pages/office.aspx"; listItem6["RowOrder"] = 3; listItem6.Update(); list.Update(); #endregion #region Create News SPListItem folderItem3 = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder); folderItem3["Title"] = "News"; folderItem3.Update(); SPListItem listItem7 = list.Items.Add(folderItem3.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem7["Title"] = "News"; listItem7["NavURL"] = "/eng/Pages/news.aspx"; listItem7["RowOrder"] = 1; listItem7.Update(); list.Update(); SPListItem listItem8 = list.Items.Add(folderItem3.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem8["Title"] = "News releases"; listItem8["NavURL"] = "/eng/Pages/releases.aspx"; listItem8["RowOrder"] = 2; listItem8.Update(); list.Update(); SPListItem listItem9 = list.Items.Add(folderItem3.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem9["Title"] = "Multimedia"; listItem9["NavURL"] = "/eng/Pages/multimedia.aspx"; listItem9["RowOrder"] = 3; listItem9.Update(); list.Update(); SPListItem listItem10 = list.Items.Add(folderItem3.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem10["Title"] = "Media advisories"; listItem10["NavURL"] = "/eng/Pages/advisories.aspx"; listItem10["RowOrder"] = 4; listItem10.Update(); list.Update(); #endregion #region Create Stay Connected SPListItem folderItem4 = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder); folderItem4["Title"] = "Stay Connected"; folderItem4.Update(); SPListItem listItem11 = list.Items.Add(folderItem4.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem11["Title"] = "Stay Connected"; listItem11["NavURL"] = ""; listItem11["RowOrder"] = 0; listItem11.Update(); SPListItem listItem12 = list.Items.Add(folderItem4.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem12["Title"] = "You Tube"; listItem12["NavURL"] = "/eng/Pages/youtube.aspx"; listItem12["RowOrder"] = 1; listItem12.Update(); SPListItem listItem13 = list.Items.Add(folderItem4.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem13["Title"] = "Twitter"; listItem13["NavURL"] = "/eng/Pages/twitter.aspx"; listItem13["RowOrder"] = 2; listItem13.Update(); SPListItem listItem14 = list.Items.Add(folderItem4.Folder.ServerRelativeUrl, SPFileSystemObjectType.File, null); //Set the values for other fields in the list listItem14["Title"] = "Feeds"; listItem14["NavURL"] = "/eng/Pages/Feeds.aspx"; listItem14["RowOrder"] = 3; listItem14.Update(); list.Update(); #endregion //adding two item that are not in a folder SPListItem item = list.Items.Add(); item["Title"] = "Terms and Conditions"; item["NavURL"] = "/eng/Pages/terms.aspx"; item["RowOrder"] = 1; item.Update(); SPListItem item2 = list.Items.Add(); item2["Title"] = "Transparency"; item2["NavURL"] = "/eng/Pages/transparency.aspx"; item2["RowOrder"] = 2; item2.Update(); list.Update(); } } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - DefaultMasterPageProcess: " + ex.Message + " " + ex.StackTrace); } }
/// <summary> /// Checks to see if the given master page exists in the site collections Master Page library /// </summary> /// <param name="properties"></param> /// <param name="_masterpage">Name of the master page to chech against</param> /// <returns></returns> private Boolean CheckIfMasterPageExist(SPWebEventProperties properties, String _masterpage) { Boolean _bln = false; try { using (SPSite site = new SPSite(properties.SiteId)) { using (SPWeb web = site.OpenWeb()) { SPList myList = web.Lists["Master Page Gallery"]; SPQuery oQuery = new SPQuery(); oQuery.Query = string.Format("<Where><Contains><FieldRef Name=\"FileLeafRef\" /><Value Type=\"File\">.master</Value></Contains></Where><OrderBy><FieldRef Name=\"FileLeafRef\" /></OrderBy>"); SPListItemCollection colListItems = myList.GetItems(oQuery); foreach (SPListItem currentItem in colListItems) { if (currentItem.Name.Trim().ToLower() == _masterpage.Trim().ToLower()) { _bln = true; break; } } } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - CheckIfMasterPageExist: " + ex.Message + " " + ex.StackTrace); } return _bln; }
/// <summary> /// A site is being deleted. /// </summary> public override void WebDeleting(SPWebEventProperties properties) { properties.Cancel = true; properties.ErrorMessage = "Site cannot be deleted"; }
private void DefaultPageLayoutProcess(SPWebEventProperties properties) { PageLayout _pageLayout; try { using (SPSite site = new SPSite(properties.SiteId)) { using (SPWeb web = site.OpenWeb()) { PublishingSite pubSiteCollection = new PublishingSite(site); PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(properties.Web); //check if pagelayout to be defaulted already exists in AvailablePageLayouts _pageLayout = (from _pl in publishingWeb.GetAvailablePageLayouts() where _pl.Name == defaultPageLayout select _pl).FirstOrDefault(); //if exists if (_pageLayout != null) { publishingWeb.SetDefaultPageLayout(_pageLayout, true); publishingWeb.Update(); } else //if does not exist { //get all AvailablePageLayouts PageLayout[] _allpageLayout = publishingWeb.GetAvailablePageLayouts(); PageLayout[] plarray = new PageLayout[_allpageLayout.Length + 1]; int ipl = -1; //transfer existing pagelayouts in AvailablePageLayouts to PageLayout[] foreach (PageLayout _itempl in _allpageLayout) { ipl++; plarray[ipl] = _itempl; } //PageLayout to be defaulted to _pageLayout = pubSiteCollection.PageLayouts["/_catalogs/masterpage/" + defaultPageLayout]; ipl++; //add to the PageLayout array plarray[ipl] = _pageLayout; //reset AvailablePageLayouts publishingWeb.SetAvailablePageLayouts(plarray, true); publishingWeb.Update(); //set DefaultPageLayout publishingWeb.SetDefaultPageLayout(_pageLayout, true); publishingWeb.Update(); web.Update(); } //Swap the page layout of the default.aspx page SwapPageLayout(publishingWeb, _pageLayout, web.Site.RootWeb.ContentTypes[_pageLayout.AssociatedContentType.Id]); } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - DefaultPageLayoutProcess: " + ex.Message + " " + ex.StackTrace); } }
/// <summary> /// A site was provisioned. /// </summary> public override void WebProvisioned(SPWebEventProperties properties) { base.WebProvisioned(properties); }
/// <summary> /// A site was deleted. /// </summary> public override void WebDeleted(SPWebEventProperties properties) { base.WebDeleted(properties); }
private void MUIProcess(SPWebEventProperties properties) { try { using (SPSite site = new SPSite(properties.Web.Site.ID)) { using (SPWeb web = site.AllWebs[properties.WebId]) { web.IsMultilingual = true; // Add support for any installed language currently not supported. SPLanguageCollection installed = SPRegionalSettings.GlobalInstalledLanguages; IEnumerable<CultureInfo> cultures = web.SupportedUICultures; foreach (SPLanguage language in installed) { CultureInfo culture = new CultureInfo(language.LCID); if (!cultures.Contains(culture)) { web.AddSupportedUICulture(culture); } } web.Update(); } } } catch (Exception ex) { Logger.WriteLog("WebProvisioning.cs - MUIProcess: " + ex.Message + " " + ex.StackTrace); } }
/// <summary> /// A site is being moved. /// </summary> public override void WebMoving(SPWebEventProperties properties) { base.WebMoving(properties); }
public override void WebDeleting(SPWebEventProperties properties) { try { var sParentItem = properties.Web.AllProperties["ParentItem"]; var sColl = sParentItem.ToString().Split(new string[] { "^^" }, StringSplitOptions.RemoveEmptyEntries); var webid = sColl[0]; var listid = sColl[1]; var itemid = sColl[2]; var sIsItem = (new Guid(listid) != Guid.Empty) ? "true" : "false"; var bIsItem = (new Guid(listid) != Guid.Empty); var xml = "<Data><Param key=\"SiteId\">" + properties.SiteId + "</Param>" + "<Param key=\"WebId\">" + properties.Web.ID + "</Param>" + "<Param key=\"ItemId\">" + itemid + "</Param>" + "<Param key=\"FString\">" + properties.Web.ServerRelativeUrl + "</Param>" + "<Param key=\"Type\">4</Param>" + "<Param key=\"UserId\">" + properties.Web.CurrentUser.ID + "</Param>" + "<Param key=\"IsItem\">" + sIsItem + "</Param></Data>"; var data = new AnalyticsData(xml, AnalyticsType.FavoriteWorkspace, AnalyticsAction.Delete); var qExec = new QueryExecutor(properties.Web); qExec.ExecuteEpmLiveQuery( FRFQueryFactory.GetQuery(data), FRFQueryParamFactory.GetParam(data)); qExec.ExecuteReportingDBNonQuery( "DELETE FROM RPTWeb WHERE [WebId]=@webid", new Dictionary <string, object>() { { "@webid", properties.WebId } }); qExec.ExecuteReportingDBNonQuery( "DELETE FROM [RPTWEBGROUPS] WHERE [WEBID] NOT IN (SELECT [WebId] FROM [RPTWeb])", new Dictionary <string, object>()); if (bIsItem) { // remove the parent item's workspaceurl field value // so the workspace icon doesn't show up in grid try { SPSecurity.RunWithElevatedPrivileges(delegate { using (var s = new SPSite(properties.SiteId)) { using (var w = s.OpenWeb(new Guid(webid))) { w.AllowUnsafeUpdates = true; var l = w.Lists[new Guid(listid)]; var i = l.GetItemById(int.Parse(itemid)); i["WorkspaceUrl"] = null; i.SystemUpdate(); // var dt = qExec.ExecuteReportingDBQuery( // "SELECT [TableName] FROM [RPTList] WHERE RPTListId = '" + l.ID + "'", new Dictionary<string, object>()); // if (dt != null && dt.Rows.Cast<DataRow>().Any()) // { // var sRptTblName = dt.Rows[0][0].ToString(); // var sDelWsUrlQuery = // @"IF EXISTS (select * from INFORMATION_SCHEMA.COLUMNS where table_name = '" + sRptTblName + @"' and column_name = 'WorkspaceUrl') // BEGIN // UPDATE " + sRptTblName + @" SET [WorkspaceUrl] = NULL WHERE [ListId] = '" + listid + @"' AND [ItemId] = " + itemid + @" // END"; // qExec.ExecuteReportingDBNonQuery(sDelWsUrlQuery, new Dictionary<string, object>()); // } } } }); } catch { } } CacheStore.Current.RemoveSafely(properties.Web.Url, new CacheStoreCategory(properties.Web).Navigation); } catch { } }
/// <summary> /// A site collection is being deleted. /// </summary> public override void SiteDeleting(SPWebEventProperties properties) { base.SiteDeleting(properties); }