public SPUser InsertUser(UserObject user) { if (user == null) { return(null); } if (string.IsNullOrEmpty(user.UserName)) { return(null); } SPUser sharepointUser = null; try { using (SPWeb varWebSite = GetWebSite()) { SPUserCollection users = varWebSite.SiteUsers; users.Add(user.UserName, user.Email, user.Name, user.Notes); AssignPermission(user.Role, string.Empty, user.UserName); sharepointUser = varWebSite.AllUsers[user.UserName]; varWebSite.Update(); } } catch (Exception ex) { var log = new AppEventLog(AppException.ExceptionMessage(ex, "InsertUser", "ClsHelper")); log.WriteToLog(); } return(sharepointUser); }
public void DeleteUser(string username) { if (string.IsNullOrEmpty(username)) { return; } try { SPUser user = GetUserObject(username); if (user == null) { return; } using (SPWeb website = GetWebSite()) { SPUserCollection varUsers = website.SiteUsers; varUsers.Remove(username); website.Update(); } } catch (Exception ex) { var log = new AppEventLog(AppException.ExceptionMessage(ex, "DeleteUser", "ClsHelper")); log.WriteToLog(); } }
/// <summary> /// Gets a SPUser object for a given login name /// </summary> /// <param name="userLogin">The loginName to look for</param> /// <returns></returns> public static SPUser GetUserFromLogin(string userLogin) { // TODO: We get a lot of warnings on these, and the Guidewire Service Account is often reflected in SharePoint. This method could use some work. Not critical ATM SPUser user = null; if (userLogin != null) { try { SPUserCollection allUsers = SPContext.Current.Web.AllUsers; var xml = XDocument.Parse(allUsers.Xml); var xmlUsers = (from item in xml.Descendants("User") where (String)item.Attribute("LoginName") == userLogin select item); if (xmlUsers.Count <XElement>() > 0) // should only be one, if less than zero user could not be found { int userID = (int)xmlUsers.First().Attribute("ID"); user = allUsers.GetByID(userID); } else { LogError(String.Format("Login {0} could not be located in SharePoint Users", userLogin == null ? "null" : userLogin), ErrorLevel.Warning); } } catch (Exception e) { LogError("GetUserFromLogin errored with the exception: " + e.Message); } } return(user); }
private SPWeb CreateMockSPWeb(bool blank, bool validUser) { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); if (!blank) { SPUserCollection users = RecorderManager.CreateMockedObject <SPUserCollection>(); if (validUser) { SPUser user = RecorderManager.CreateMockedObject <SPUser>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetCollection(new string[] { }), users); recorder.ExpectAndReturn(users.Count, 1); recorder.ExpectAndReturn(users[0].LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgemployee")); recorder.ExpectAndReturn(users[0], user); recorder.ExpectAndReturn(user.ID, 1).RepeatAlways(); recorder.ExpectAndReturn(user.Name, "SPG Employee").RepeatAlways(); recorder.ExpectAndReturn(user.LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgemployee")).RepeatAlways(); } } else { using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetCollection(new string[] { }), users); recorder.ExpectAndReturn(users.Count, 0); } } } return(web); }
/// ****************************************************************************************** /// <summary> /// Method to return concatenated value of email addresses of site collection administrators /// </summary> /// ****************************************************************************************** public string GetAdminsEmailAddresses() { string siteAdminsEmailAddresses = string.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb web = site.OpenWeb()) { //Get the Site Administrators of current site SPUserCollection siteAdminsCollection = web.SiteAdministrators; foreach (SPUser oSPUser in siteAdminsCollection) { //If Email Address of a site administrator exists if (!string.IsNullOrEmpty(oSPUser.Email)) { if (string.IsNullOrEmpty(siteAdminsEmailAddresses)) { siteAdminsEmailAddresses = oSPUser.Email; } else { siteAdminsEmailAddresses = siteAdminsEmailAddresses + "," + oSPUser.Email; } } } } } }); return(siteAdminsEmailAddresses); }
public static void SendWarningMessageToGroup(SPWeb web, string groupName, string subject, string bodyHTML) { SPGroupCollection groupCollection = web.SiteGroups; foreach (SPGroup group in groupCollection) { if (group.Name == groupName) { string sender1 = sender; if (!string.IsNullOrEmpty(web.Site.RootWeb.Title)) { sender1 = string.Format(@"{1}<{0}>", sender, web.Site.RootWeb.Title); } #if DEBUG SPEmail.EmailGenerator.SendMail(web, sender1, web.CurrentUser.Email, subject, bodyHTML, true, string.Empty, string.Empty); #else SPUserCollection userCollection = group.Users; foreach (SPUser user in userCollection) { if (IsValidEmailAddress(user.Email)) { SPEmail.EmailGenerator.SendMail(web, sender1, user.Email, subject, bodyHTML, true, string.Empty, string.Empty); } } break; #endif } } }
public static void CreateSubSiteGroup(SPWeb web, string groupName, string PermissionLevel, string groupDescription) { try { web.AllowUnsafeUpdates = true; SPUserCollection users = web.AllUsers; SPUser owner = web.SiteAdministrators[0]; SPMember member = web.SiteAdministrators[0]; SPGroupCollection groups = web.SiteGroups; groups.Add(groupName, member, owner, groupDescription); SPGroup newSPGroup = groups[groupName]; newSPGroup.OnlyAllowMembersViewMembership = false; newSPGroup.Update(); SPRoleDefinition role = web.RoleDefinitions[PermissionLevel]; SPRoleAssignment roleAssignment = new SPRoleAssignment(newSPGroup); roleAssignment.RoleDefinitionBindings.Add(role); web.RoleAssignments.Add(roleAssignment); web.Update(); web.AllowUnsafeUpdates = false; } catch (Exception ex) { ULSLogger.LogErrorInULS(ex.Message, TraceSeverity.Unexpected); } }
/// <summary> /// Creates a subsite for a SharePoint v3 site /// </summary> /// <param name="ParentSiteURL">SharePoint v3 site URL</param> /// <param name="SiteURLName">Subsite name</param> /// <param name="SiteTitle">Subsite title</param> /// <param name="SiteDescription">Subsite description</param> /// <param name="SiteLCID">Sibsite LCID</param> /// <param name="OverwriteIfExists">if true, the existing subsite with the same name will be deleted and created again.</param> /// <param name="OutNewSiteURL">the method will return the full URL of the subsite</param> /// <param name="ResultText">the method will return text log of the operations performed.</param> /// <returns>true if the subsite is successfully created.</returns> public bool CreateSite(string parentSiteURL, string siteURLName, string siteTitle, string siteDescription, uint siteLCID, bool overwriteIfExists, ref string outNewSiteURL, ref string resultText) { bool result = false; //string testResult = ""; string subSiteFullName = CleanURL(parentSiteURL) + "/" + siteURLName; outNewSiteURL = subSiteFullName; resultText = String.Format(TextResources.AttemptingToCreateSite, subSiteFullName) + Environment.NewLine; //wrapping in try catch as this will be executed in a different thread try { SPSite parentSite = new SPSite(parentSiteURL); SPWeb siteWeb = parentSite.OpenWeb(); SPWebCollection subSites = siteWeb.Webs; string currentTemplate = siteWeb.WebTemplate; string siteTestStatus; if (TestSharePointV3Site(subSiteFullName, out siteTestStatus)) { //site already exists resultText += TextResources.SiteExists + System.Environment.NewLine; if (overwriteIfExists) { //delete site SPUserCollection siteUsers = siteWeb.SiteUsers; //emptying site users collection int numUsers = siteUsers.Count; for (int userIndex = numUsers; userIndex == 1; userIndex--) { if (!(parentSite.Owner.Sid == siteWeb.SiteUsers[userIndex].Sid)) { siteWeb.SiteUsers.Remove(userIndex); } } subSites.Delete(siteURLName); } else { //dont need to overwrite, exiting result = true; return(result); } } subSites.Add(siteURLName, siteTitle, siteDescription, siteLCID, currentTemplate, true, false); string siteTestResult; if (TestSharePointV3Site(subSiteFullName, out siteTestResult)) { result = true; resultText += TextResources.SiteCreated + System.Environment.NewLine; } } catch (System.Exception ex) { resultText += ex.Message + System.Environment.NewLine; } return(result); }
public SPUserCollectionInstance(ObjectInstance prototype, SPUserCollection userCollection) : this(prototype) { if (userCollection == null) { throw new ArgumentNullException("userCollection"); } m_userCollection = userCollection; }
private void IfMatchAddUser(SPUserCollection userCollection, string loginName, bool exactMatch, bool checkDisplayName, SPSecurableObject securableObject, SPGroup group, IList <e.Permission> result) { foreach (SPUser user in userCollection) { bool found = false; if (!string.IsNullOrEmpty(user.LoginName)) { if (exactMatch && (user.LoginName.ToLower() == loginName.ToLower())) { result.Add(new e.Permission() { SecurableObject = securableObject, PermissionLevels = GetPermissionLevels(securableObject, group, user), SharePointGroup = group, LoginName = user.LoginName, DisplayName = user.Name }); found = true; } else if (user.LoginName.ToLower().Contains(loginName.ToLower())) { result.Add(new e.Permission() { SecurableObject = securableObject, PermissionLevels = GetPermissionLevels(securableObject, group, user), SharePointGroup = group, LoginName = user.LoginName, DisplayName = user.Name }); found = true; } } if (!found) { if (checkDisplayName) { if (!string.IsNullOrEmpty(user.Name)) { if (exactMatch && (user.Name.ToLower() == loginName.ToLower())) { result.Add(new e.Permission() { SecurableObject = securableObject, PermissionLevels = GetPermissionLevels(securableObject, group, user), SharePointGroup = group, LoginName = user.LoginName, DisplayName = user.Name }); found = true; } else if (user.Name.ToLower().Contains(loginName.ToLower())) { result.Add(new e.Permission() { SecurableObject = securableObject, PermissionLevels = GetPermissionLevels(securableObject, group, user), SharePointGroup = group, LoginName = user.LoginName, DisplayName = user.Name }); found = true; } } } } } }
private static SPUser GetSPUser(SPWeb web, string login) { string[] userQuery = { login }; SPUserCollection usersFound = web.SiteUsers.GetCollection(userQuery); if ((usersFound != null) && (usersFound.Count == 1) && (usersFound[0].LoginName == login)) { return(usersFound[0]); } else { return(null); } }
private void AddGroupToParentWeb(SPWeb web, string groupName, SPRoleType roleType) { SPUserCollection users = web.AllUsers; SPGroup group = web.SiteGroups.GetByName(groupName); if (group != null) { SPRoleDefinition role = web.RoleDefinitions.GetByType(roleType); SPRoleAssignment roleAssignment = new SPRoleAssignment(group); roleAssignment.RoleDefinitionBindings.Add(role); web.RoleAssignments.Add(roleAssignment); web.Update(); } }
public UserCollectionNode(Object parent, SPUserCollection collection) { this.Text = SPMLocalization.GetString("Users_Text"); this.ToolTipText = SPMLocalization.GetString("Users_ToolTip"); this.Name = "User Collection"; this.Tag = collection; this.SPParent = parent; int index = Program.Window.Explorer.AddImage(this.ImageUrl()); this.ImageIndex = index; this.SelectedImageIndex = index; this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
public static void SetPermUser(string spsURL, string libName, string fPath, string usrName, string lvlAccess) { // lvlAccess - Full Control; Design; Contribute; Read; View Only; Limited Access; using (SPSite site = new SPSite(spsURL)) { using (SPWeb web = site.OpenWeb()) { SPFolder eXfolder = web.GetFolder(fPath); SPUserCollection spc = web.SiteUsers; SPUser username = spc[usrName]; SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)username); eXfolder.Item.BreakRoleInheritance(true); roleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions[lvlAccess]); eXfolder.Item.RoleAssignments.Add(roleAssignment); } } }
public List <string> getAllUsersInSiteCollection() { List <string> UserNames = new List <string>(); using (SPSite site = new SPSite(SiteUrl)) { SPUserCollection usercoll = site.RootWeb.SiteUsers; foreach (SPUser user in usercoll) { UserNames.Add(user.Name); } } return(UserNames); }
public UserCollectionNode(Object parent, SPUserCollection collection) { this.Text = SPMLocalization.GetString("Users_Text"); this.ToolTipText = SPMLocalization.GetString("Users_ToolTip"); this.Name = "User Collection"; this.Tag = collection; this.SPParent = parent; int index = Program.Window.Explorer.AddImage(this.ImageUrl()); this.ImageIndex = index; this.SelectedImageIndex = index; this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
private string PrintAdmins(SPUserCollection admins) { StringBuilder s = new StringBuilder(); for (int i = 0; i < admins.Count; i++) { s.Append(string.Format("{0}", admins[i].Name)); if (i != admins.Count - 1) { s.Append(", "); } } return(s.ToString()); }
/// <summary> /// Add group to SPWeb and set permission for this group /// </summary> /// <param name="web"></param> /// <param name="groupName"></param> /// <param name="groupDescription"></param> /// <param name="role"></param> /// <param name="member"></param> public static void CreateNewGroup(this SPWeb web, string groupName, string groupDescription, SPRoleType role) { if (string.IsNullOrEmpty(groupName)) { return; } try { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite spSite = new SPSite(web.Site.ID)) { using (SPWeb spWeb = spSite.OpenWeb(web.ID)) { SPUserCollection users = spWeb.AllUsers; SPUser owner = users[spWeb.Author.LoginName]; SPMember member = users[spWeb.Author.LoginName]; //Add the group to the SPWeb web SPGroupCollection groups = spWeb.SiteGroups; var isExits = groups.Cast <SPGroup>().FirstOrDefault(p => p.Name == groupName); if (isExits == null) { groups.Add(groupName, member, owner, groupDescription); } //Associate the group with SPWeb //spWeb.AssociatedGroups.Add(spWeb.SiteGroups[groupName]); spWeb.Update(); //Assignment of the roles to the group. SPRoleAssignment assignment = new SPRoleAssignment(spWeb.SiteGroups[groupName]); SPRoleDefinition _role = spWeb.RoleDefinitions.GetByType(role); assignment.RoleDefinitionBindings.Add(_role); spWeb.RoleAssignments.Add(assignment); } } }); } catch { // Not catch exception because check group exists } }
public string getUserLoginName(string UserName) { string t = ""; using (SPSite site = new SPSite(SiteUrl)) { SPUserCollection usercoll = site.RootWeb.SiteUsers; foreach (SPUser user in usercoll) { if (user.Name == UserName) { t = user.LoginName; break; } } } return(t); }
public static SPUser UserExists(SPUserCollection users, string name) { SPUser result = null; /*if (string.IsNullOrEmpty(name) || * (name.Length > 255) || * (users == null) || * (users.Count == 0)) * return false; * else * {*/ foreach (SPUser user in users) { if ((user.Name == name) | (user.LoginName == name)) { result = user; } } // } return(result); }
public static string GetEmailAddressFromGroup(SPWeb web) { string EmailAddress = string.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite Osite = new SPSite(web.Site.ID)) { using (SPWeb OWeb = Osite.OpenWeb()) { SPGroup Ogroup = OWeb.Groups["IssueAdmin"]; SPUserCollection users = Ogroup.Users; foreach (SPUser user in users) { EmailAddress += user.Email.ToString() + ";"; } } } }); return(EmailAddress); }
public static void CreateNewGroup(this SPWeb web, string groupName, string groupDescription) { if (string.IsNullOrEmpty(groupName)) { return; } try { SPSecurity.RunWithElevatedPrivileges(delegate() { SPUserCollection users = web.AllUsers; SPUser owner = users[web.Author.LoginName]; SPMember member = users[web.Author.LoginName]; try { //Add the group to the SPWeb web SPGroupCollection groups = web.SiteGroups; groups.Add(groupName, member, owner, groupDescription); //Associate the group with SPWeb web.AssociatedGroups.Add(web.SiteGroups[groupName]); web.Update(); } catch { } //Assignment of the roles to the group. SPRoleAssignment assignment = new SPRoleAssignment(web.SiteGroups[groupName]); SPRoleDefinition _role = web.RoleDefinitions.GetByType(SPRoleType.Contributor); assignment.RoleDefinitionBindings.Add(_role); web.RoleAssignments.Add(assignment); }); } catch { // Not catch exception because check group exists } }
public DataTable GetUsersDataTable() { DataTable dt = newDataTable(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPWeb web = SPContext.Current.Web) { SPUserCollection users1 = web.AllUsers; SPUserCollection users2 = web.SiteUsers; SPUserCollection users3 = web.Users; SPList list = web.SiteUserInfoList; // web.Lists["User Information List"]; foreach (SPListItem item in list.Items) { if (!item["ContentType"].ToString().Equals("Person")) { continue; } DataRow dr = dt.NewRow(); dr["name"] = item["Title"]; dr["loginName"] = item["Name"]; //dr["Email"] = item["Email"]; dr["picture"] = item["Picture"]; dt.Rows.Add(dr); //string name = item["Title"] + ""; //string loginName = item["Name"] + ""; //string Email = item["Email"] + ""; //string picture = item["Picture"] + ""; //... 其他属性 } } }); return(dt); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite sitecollection = new SPSite(Url)) { using (SPWeb web = sitecollection.OpenWeb()) { SPList list = web.Lists["Aufgaben"]; SPListItem listitem = list.Items.Add(); SPContentType ConType = list.ContentTypes[ContentType.ToString()]; if (ConType != null) { listitem["ContentTypeId"] = ConType.Id; } if (!String.IsNullOrEmpty(Title) & listitem.Fields.ContainsField("Title")) { listitem["Title"] = Title.ToString(); } if (!String.IsNullOrEmpty(Descript) & (listitem.Fields.ContainsField("Beschreibung") | listitem.Fields.ContainsField("Body"))) { listitem["Beschreibung"] = Descript.ToString(); } if (!String.IsNullOrEmpty(Link) & listitem.Fields.ContainsField("Link")) { LinkFieldValue lfValue = new LinkFieldValue(); lfValue.NavigateUrl = Link.ToString(); lfValue.Text = "Link zu Dokument"; lfValue.UseDefaultIcon = false; listitem["Link"] = lfValue; } if (!String.IsNullOrEmpty(AccountName) & listitem.Fields.ContainsField("AssignedTo")) { SPUserCollection users = web.Users; SPUser user = UserExists(users, AccountName.ToString()); if (user != null) { listitem["AssignedTo"] = user; } else { SPGroupCollection groups = web.Groups; if (GroupExists(groups, AccountName.ToString())) { listitem["AssignedTo"] = web.Groups[AccountName.ToString()]; } } } if (!String.IsNullOrEmpty(Quelle) & listitem.Fields.ContainsField("Aufgabenquelle")) { listitem["Aufgabenquelle"] = Quelle.ToString(); } if ((TargetDate.ToString() != string.Empty) & (listitem.Fields.ContainsField("DueDate"))) { listitem["DueDate"] = TargetDate; } if (listitem.Fields.ContainsField("WorkflowID")) { listitem["WorkflowID"] = WorkflowID; } listitem.Update(); TaskID = listitem.ID; } } }); return(base.Execute(executionContext)); }
public void AddBuildTeamSecurityGroups(SPWeb ew, GridGanttSettings settings, SPListItem eI) { string teamPerm = string.Empty; try { teamPerm = settings.BuildTeamPermissions; } catch { } if (!string.IsNullOrEmpty(teamPerm)) { string[] strOuter = settings.BuildTeamPermissions.Split(new string[] { "|~|" }, StringSplitOptions.None); //SPListItem eI = ew.Lists[base.ListUid].GetItemById(base.ItemID); foreach (string strInner in strOuter) { string[] strInnerMost = strInner.Split('~'); SPGroup g = null; SPRoleDefinition r = null; try { g = ew.SiteGroups.GetByID(Convert.ToInt32(strInnerMost[0])); r = ew.RoleDefinitions.GetById(Convert.ToInt32(strInnerMost[1])); } catch { } if (g != null && r != null) { if (r.Type != SPRoleType.Guest) { SPRoleAssignment assign = new SPRoleAssignment(g); assign.RoleDefinitionBindings.Add(r); AddNewItemLvlPerm(eI, ew, assign); //Adding users with Full Control permission levels to Owners group. if (r.Type == SPRoleType.Administrator) //Full Control Permission Level { //Add users to Owners group. SPUserCollection groupUsers = g.Users; foreach (SPRoleAssignment role in eI.RoleAssignments) { try { if (role.Member.GetType() == typeof(SPGroup)) { SPGroup group = (SPGroup)role.Member; if (group.Name.EndsWith("Owner")) { try { foreach (SPUser user in groupUsers) { group.AddUser(user); } group.Update(); } catch { } } } } catch { } } } } else { // create our custom limited access role SPRoleDefinition roleDef = new SPRoleDefinition(); try { roleDef = ew.RoleDefinitions["Limited Access Permission"]; } catch (SPException) { ew.AllowUnsafeUpdates = true; // give it a name and description roleDef.Name = "Limited Access Permission"; roleDef.Description = "Identical to standard Limited Access rights. Used to provide access to parent objects of uniquely permissioned content"; // apply the base permissions required roleDef.BasePermissions = SPBasePermissions.ViewFormPages | SPBasePermissions.Open | SPBasePermissions.BrowseUserInfo | SPBasePermissions.UseClientIntegration | SPBasePermissions.UseRemoteAPIs; // add it to the web ew.RoleDefinitions.Add(roleDef); ew.Update(); } try { SPRoleAssignment assign = new SPRoleAssignment(g); assign.RoleDefinitionBindings.Add(roleDef); AddNewItemLvlPerm(eI, ew, assign); } catch { } } } } } //return createdGrps; }
private void LoadDropDownList() { CmbRequestFrom.Items.Clear(); CmbRequestFrom.Items.Add(new ListItem { Text = "All", Value = "0", Selected = true }); CmbLeaveType.Items.Clear(); CmbLeaveType.Items.Add(new ListItem { Text = "ALL", Value = "ALL" }); CmbLeaveType.Items.Add(new ListItem { Text = "Paid Leave", Value = "Paid Leave" }); CmbLeaveType.Items.Add(new ListItem { Text = "Sick Leave", Value = "Sick Leave" }); CmbLeaveType.Items.Add(new ListItem { Text = "Casual Leave", Value = "Casual Leave" }); CmbLeaveType.Items.Add(new ListItem { Text = "Optional", Value = "Optional" }); CmbLeaveType.Items.Add(new ListItem { Text = "LOP", Value = "LOP" }); SPSecurity.RunWithElevatedPrivileges(delegate { using (var site = new SPSite(SPContext.Current.Site.Url)) { using (var web = site.OpenWeb()) { foreach (SPGroup spGroup in web.Groups) { if (spGroup.Name.ToString() == "Employee") { SPUserCollection spuseringroup = spGroup.Users; foreach (SPUser spUser in spuseringroup) { if (!spUser.IsDomainGroup && !spUser.IsSiteAdmin && !spUser.IsSiteAuditor && spUser.Name != "System Account") { CmbRequestFrom.Items.Add(new ListItem { Text = spUser.Name, Value = spUser.ID.ToString() }); } } } } } } }); }
/// <summary> /// Adds SharePoint group to SharePoint v3 site /// </summary> /// <param name="SiteURL">SharePoint v3 site URL</param> /// <param name="GroupName">Group to be added</param> /// <param name="GroupOwner">Group owner. If the user does not belong to site it will be added.</param> /// <param name="DefaultUser">Default group user. If the user does not belong to site it will be added.</param> /// <param name="OverwriteIfExists">If set, the group will be removed and created again, if it exists.</param> /// <param name="ResultText">The method returns log of operations performed.</param> /// <returns>true if the group is successfully added.</returns> public bool CreateUsersGroup(string siteURL, string groupName, CS4User groupOwner, CS4User defaultUser, bool overwriteIfExists, ref string resultText) { bool result = false; resultText = String.Format(TextResources.AttemptingToCreateGroup, groupName) + Environment.NewLine; SPSite site = null; SPWeb siteWeb = null; SPGroupCollection groups = null; try { site = new SPSite(siteURL); siteWeb = site.OpenWeb(); groups = siteWeb.SiteGroups; } catch (System.Exception ex) { resultText += TextResources.CantCreateGroup + ex.Message + System.Environment.NewLine; return(result); } SPUser user = null; bool createDefaultUser = false; try { user = siteWeb.SiteUsers[defaultUser.UserLoginWithDomain]; } catch { //user does not exist createDefaultUser = true; } SPMember owner = null; bool createGroupOwner = false; try { owner = siteWeb.SiteUsers[groupOwner.UserLoginWithDomain]; } catch { createGroupOwner = true; } try { if (createDefaultUser) { AddSiteUser(defaultUser); user = siteWeb.SiteUsers[defaultUser.UserLoginWithDomain]; } if (createGroupOwner) { AddSiteUser(groupOwner); owner = siteWeb.SiteUsers[groupOwner.UserLoginWithDomain]; } } catch (System.Exception ex) { resultText += TextResources.NoGroupOwnerOrDefaultUser + ex.Message + Environment.NewLine; return(result); } SPGroup group = null; bool groupExists = false; try { group = groups[groupName]; groupExists = true; resultText += TextResources.GroupExists + Environment.NewLine; } catch { //group does not exist } try { if (groupExists) { if (overwriteIfExists) { SPUserCollection groupUsers = group.Users; //emptying group users collection foreach (SPUser groupUser in groupUsers) { group.RemoveUser(groupUser); } groups.Remove(groupName); } else { result = true; return(result); } } groups.Add(groupName, owner, user, String.Empty); resultText += TextResources.GroupCreated + System.Environment.NewLine; result = true; } catch (System.Exception ex) { resultText += ex.Message; } return(result); }
protected void Page_Load(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(Convert.ToString(Request.QueryString["SigmaId"]))) { PassportCategoryId = Convert.ToInt32(Convert.ToString(Request.QueryString["SigmaId"])); MeetingCat = Convert.ToString(Request.QueryString["Group"]); Usr = Convert.ToString(Request.QueryString["User"]); } SPGroup testingOwnersGroup = SPContext.Current.Web.SiteGroups[MeetingCat]; SPUserCollection userColl = testingOwnersGroup.Users; DataTable dtUsers = new DataTable(); DataColumn dcName = new DataColumn("Name", typeof(string)); DataColumn dcLoginName = new DataColumn("LoginName", typeof(string)); dtUsers.Columns.Add(dcName); dtUsers.Columns.Add(dcLoginName); dtUsers.AcceptChanges(); foreach (SPUser user in userColl) { if (!(user.Name == "NT AUTHORITY\\Authenticated Users") && !(user.IsDomainGroup) && !(user.Name == "System Account")) { DataRow dr = dtUsers.NewRow(); dr["Name"] = user.Name; dr["LoginName"] = user.LoginName; dtUsers.Rows.Add(dr); dtUsers.AcceptChanges(); } } LB_MainSelection.DataSource = dtUsers; LB_MainSelection.DataTextField = "Name"; LB_MainSelection.DataValueField = "LoginName"; LB_MainSelection.DataBind(); LB_CentralData.DataSource = dtUsers; LB_CentralData.DataTextField = "Name"; LB_CentralData.DataValueField = "LoginName"; LB_CentralData.DataBind(); if (!Page.IsPostBack) { if (!(string.IsNullOrEmpty(Usr)) && !(Usr.Equals("undefined"))) { SPUser myUser = currentWeb.EnsureUser(Usr); DataTable SelectedUsers = new DataTable(); DataColumn SelctddcName = new DataColumn("Name", typeof(string)); DataColumn SelctddcLoginName = new DataColumn("LoginName", typeof(string)); SelectedUsers.Columns.Add(SelctddcName); SelectedUsers.Columns.Add(SelctddcLoginName); SelectedUsers.AcceptChanges(); DataRow dr = SelectedUsers.NewRow(); dr["Name"] = myUser.Name; dr["LoginName"] = myUser.LoginName; SelectedUsers.Rows.Add(dr); SelectedUsers.AcceptChanges(); LB_SelectedUserList.DataSource = SelectedUsers; LB_SelectedUserList.DataTextField = "Name"; LB_SelectedUserList.DataValueField = "LoginName"; LB_SelectedUserList.DataBind(); } var hdnhidden1 = HiddenField1.ClientID; var hdnhidden2 = HiddenField2.ClientID; string script = string.Format("var hdn1 = '{0}';var hdn2 = '{1}';", hdnhidden1, hdnhidden2); Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "myScript", script, true); } } catch (Exception ex) { ULSLogger.LogErrorInULS("Inside catch in Page_Load() in PWC.Process.SixSigma Feature..Error is--" + ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { /*using (TPP bd = new TPP()) * { * * }*/ /*TPP bd = new TPP(); * bd.Materials.Add(new Material() * { * Assortment = "erhrh", * DesignOfStandard = "htdfdh", * Name = "rth", * Stamp = "hfhrfr" * }); * bd.SaveChanges();*/ TPP bd = new TPP(); SPSite site = SPControl.GetContextSite(Context); SPWeb web = site.OpenWeb(); /*SPListCollection collList = web.Lists; * * foreach (var oList in collList) * { * Console.WriteLine("Title: {0} Created: {1}", oList., oList.Created.ToString()); * }*/ //SPUser developer = web.Users.GetByID(route.NameOfDeveloper); //cell4.Text = developer.LoginName; SPGroupCollection collGroups = web.Groups; foreach (SPGroup oGroup in collGroups) { foreach (SPUser user in oGroup.Users) { routeNameOfDeveloper.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardAgreed.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardApproved.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardChecked.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardDeveloper.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); routeCardNormController.Items.Add( new ListItem(user.LoginName, user.ID.ToString())); } } //add materials foreach (var mat in bd.Materials) { //fill dropdowns technologicalProcessMaterial.Items.Add( new ListItem(mat.MaterialId.ToString(), mat.MaterialId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = mat.MaterialId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = mat.Assortment; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = mat.Name; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = mat.Stamp; row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = mat.DesignOfStandard; row.Cells.Add(cell5); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Materials.Attach(mat); lbd.Entry(mat).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell6 = new TableCell(); cell6.Controls.Add(button); row.Cells.Add(cell6); materials.Rows.Add(row); } //fill Equipment table foreach (var eqip in bd.Equipments) { //add to dropdown operationEquipment.Items.Add( new ListItem(eqip.EquipmentId.ToString(), eqip.EquipmentId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = eqip.EquipmentId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = eqip.DetailNumber.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = eqip.Name; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = eqip.Quantity.ToString(); row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = eqip.Department; row.Cells.Add(cell5); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Equipments.Attach(eqip); lbd.Entry(eqip).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell6 = new TableCell(); cell6.Controls.Add(button); row.Cells.Add(cell6); equipments.Rows.Add(row); } //add rigging foreach (var rig in bd.Riggings) { //add to dropdowns operationRigging.Items.Add( new ListItem(rig.RiggingId.ToString(), rig.RiggingId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = rig.RiggingId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = rig.Name; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = rig.TypeOfTool; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = rig.Quantity.ToString(); row.Cells.Add(cell4); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Riggings.Attach(rig); lbd.Entry(rig).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell5 = new TableCell(); cell5.Controls.Add(button); row.Cells.Add(cell5); riggings.Rows.Add(row); } //fill operations table foreach (var oper in bd.Operations) { //add to dropdowns technologicalProcessOperation.Items.Add( new ListItem(oper.OperationId.ToString(), oper.OperationId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = oper.OperationId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = oper.Name; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = oper.Number.ToString(); row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = oper.TransitionId.ToString(); row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = oper.TransitionName; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); cell6.Text = oper.EquipmentId.ToString(); row.Cells.Add(cell6); TableCell cell7 = new TableCell(); cell7.Text = oper.RiggingId.ToString(); row.Cells.Add(cell7); TableCell cell8 = new TableCell(); cell8.Text = oper.DepartmentNumber.ToString(); row.Cells.Add(cell8); TableCell cell9 = new TableCell(); cell9.Text = oper.SiteNumber.ToString(); row.Cells.Add(cell9); TableCell cell10 = new TableCell(); cell10.Text = oper.WorkplaceNumber.ToString(); row.Cells.Add(cell10); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Operations.Attach(oper); lbd.Entry(oper).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell11 = new TableCell(); cell11.Controls.Add(button); row.Cells.Add(cell11); operations.Rows.Add(row); } //add transitions foreach (var trans in bd.Transitions) { //add to dropdowns operationTransition.Items.Add( new ListItem(trans.TransitionId.ToString(), trans.TransitionId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = trans.TransitionId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = trans.TransitionNumber.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = trans.Keyword; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = trans.TransitionType; row.Cells.Add(cell4); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Transitions.Attach(trans); lbd.Entry(trans).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell5 = new TableCell(); cell5.Controls.Add(button); row.Cells.Add(cell5); transitions.Rows.Add(row); } //fill TechnologicalProcesses foreach (var tp in bd.TechnologicalProcesseses) { //add to routes this.routeTechProc.Items.Add( new ListItem(tp.TechProcId.ToString(), tp.TechProcId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = tp.TechProcId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = tp.Name; row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = tp.OperationId.ToString(); row.Cells.Add(cell3); TableCell cell4 = new TableCell(); cell4.Text = tp.MaterialId.ToString(); row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = tp.TypeByExecution; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); cell6.Text = tp.ActNumber.ToString(); row.Cells.Add(cell6); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.TechnologicalProcesseses.Attach(tp); lbd.Entry(tp).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell7 = new TableCell(); cell5.Controls.Add(button); row.Cells.Add(cell7); technologicalProcesses.Rows.Add(row); } //fill route foreach (var route in bd.Routes) { //add to route card this.routeCardRoute.Items.Add( new ListItem(route.RouteId.ToString(), route.RouteId.ToString())); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = route.RouteId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = route.TechProcId.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = route.NameTechProc; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); SPUserCollection users = web.SiteUsers; SPUser user = users.GetByID(route.NameOfDeveloper); //SPUser developer = web.Users.GetByID(route.NameOfDeveloper); //cell4.Text = developer.LoginName; //cell4.Text = route.NameOfDeveloper.ToString(); cell4.Text = user.LoginName; row.Cells.Add(cell4); TableCell cell5 = new TableCell(); cell5.Text = route.DetailsDesignation; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); cell6.Text = route.DetailsName; row.Cells.Add(cell6); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.Routes.Attach(route); lbd.Entry(route).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell7 = new TableCell(); cell7.Controls.Add(button); row.Cells.Add(cell7); routes.Rows.Add(row); } //fill routeCard foreach (var rc in bd.RouteCars) { TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = rc.RouteCarId.ToString(); row.Cells.Add(cell1); TableCell cell2 = new TableCell(); cell2.Text = rc.RouteId.ToString(); row.Cells.Add(cell2); TableCell cell3 = new TableCell(); cell3.Text = rc.CompanyName; row.Cells.Add(cell3); TableCell cell4 = new TableCell(); SPUserCollection users = web.SiteUsers; SPUser user = users.GetByID(rc.Developer); //cell4.Text = rc.Developer.ToString(); cell4.Text = user.LoginName; row.Cells.Add(cell4); TableCell cell5 = new TableCell(); //cell5.Text = rc.Checked.ToString(); user = users.GetByID(rc.Checked); cell5.Text = user.LoginName; row.Cells.Add(cell5); TableCell cell6 = new TableCell(); //cell6.Text = rc.Agreed.ToString(); user = users.GetByID(rc.Agreed); cell6.Text = user.LoginName; row.Cells.Add(cell6); TableCell cell7 = new TableCell(); //cell7.Text = rc.Approved.ToString(); user = users.GetByID(rc.Approved); cell7.Text = user.LoginName; row.Cells.Add(cell7); TableCell cell8 = new TableCell(); //cell8.Text = rc.NormСontroller.ToString(); user = users.GetByID(rc.NormСontroller); cell8.Text = user.LoginName; row.Cells.Add(cell8); Button button = new Button(); button.Text = "Delete"; button.Click += (s, e1) => { TPP lbd = new TPP(); lbd.RouteCars.Attach(rc); lbd.Entry(rc).State = System.Data.Entity.EntityState.Deleted; lbd.SaveChanges(); Response.Redirect(Request.RawUrl); }; TableCell cell9 = new TableCell(); cell9.Controls.Add(button); row.Cells.Add(cell9); routeCards.Rows.Add(row); } }