/// <summary> /// Enables public folders for a company /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEnablePublicFolders_Click(object sender, EventArgs e) { ADGroups groups = null; ExchCmds powershell = null; try { // Initialize groups = new ADGroups(Config.Username, Config.Password, Config.PrimaryDC); powershell = new ExchCmds(Config.ExchangeURI, Config.Username, Config.Password, Config.ExchangeConnectionType, Config.PrimaryDC); // Get company code string companyCodeWithSpaces = CPContext.SelectedCompanyCode; string companyCodeWithoutSpaces = companyCodeWithSpaces.Replace(" ", string.Empty); // Create groups groups.Create(Retrieve.GetCompanyExchangeOU, "PublicFolderAdmins@" + companyCodeWithoutSpaces, "Public Folder Administrators", true, ADGroups.GroupType.Universal, false); groups.Create(Retrieve.GetCompanyExchangeOU, "PublicFolderUsers@" + companyCodeWithoutSpaces, "Public Folder Users", true, ADGroups.GroupType.Universal, false); // Modify membership groups.ModifyMembership("PublicFolderAdmins@" + companyCodeWithoutSpaces, "Admins@" + companyCodeWithoutSpaces, System.DirectoryServices.AccountManagement.IdentityType.Name, System.DirectoryServices.AccountManagement.IdentityType.Name, false, false); groups.ModifyMembership("PublicFolderUsers@" + companyCodeWithoutSpaces, "AllUsers@" + companyCodeWithoutSpaces, System.DirectoryServices.AccountManagement.IdentityType.Name, System.DirectoryServices.AccountManagement.IdentityType.Name, false, false); // Enable security groups as distribution groups so we can add to public folders powershell.Enable_DistributionGroup(companyCodeWithoutSpaces, "PublicFolderAdmins@" + companyCodeWithoutSpaces, true); powershell.Enable_DistributionGroup(companyCodeWithoutSpaces, "PublicFolderUsers@" + companyCodeWithoutSpaces, true); // Create public folder powershell.New_PublicFolder(companyCodeWithSpaces); // Remove the default permissions powershell.Remove_PublicFolderDefaultPermissions(companyCodeWithSpaces, Config.ExchangeVersion); // Add permissions powershell.Add_PublicFolderClientPermission(companyCodeWithSpaces); // Update the database SQLPublicFolders.Update_PublicFolderForCompany(companyCodeWithSpaces, true); // Set new view panelDisablePublicFolders.Visible = false; panelEnablePublicFolders.Visible = false; panelEditPublicFolders.Visible = true; // Get public folders GetPublicFolders(); } catch (Exception ex) { notification1.SetMessage(controls.notification.MessageType.Error, "Could not enable public folders: " + ex.Message); } finally { if (powershell != null) powershell.Dispose(); if (groups != null) groups.Dispose(); } }