当前位置: 首页>>代码示例>>C#>>正文


C# SPWeb.EnsureUser方法代码示例

本文整理汇总了C#中SPWeb.EnsureUser方法的典型用法代码示例。如果您正苦于以下问题:C# SPWeb.EnsureUser方法的具体用法?C# SPWeb.EnsureUser怎么用?C# SPWeb.EnsureUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SPWeb的用法示例。


在下文中一共展示了SPWeb.EnsureUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: create_group

        protected SPGroup create_group(string group_name, SPWeb web)
        {
            SPUser user = web.EnsureUser("Administrator");
            web.SiteGroups.Add(group_name, user, null, group_name);
            SPGroup group = web.SiteGroups[group_name];
            web.Update();

            SPRoleAssignment assignment = new SPRoleAssignment(group);
            SPRoleDefinition role = web.RoleDefinitions["读取"];
            assignment.RoleDefinitionBindings.Add(role);
            web.RoleAssignments.Add(assignment);

            return group;
        }
开发者ID:ricardocarneiro,项目名称:SharePoint-1,代码行数:14,代码来源:Groups.EventReceiver.cs

示例2: AddAgendaToMeetingWorkspace

        private void AddAgendaToMeetingWorkspace(SPWeb boardWeb, string meetingWorkspaceURL, string agendaTitle, SPUser sponsor, int agendaID, string presenterName, int agendaOrder)
        {
            SPFieldUrlValue workspaceURL = new SPFieldUrlValue(meetingWorkspaceURL);

               SPMeeting meetingSites = SPMeeting.GetMeetingInformation(boardWeb);
               SPWebCollection meetingWorkspaces = meetingSites.GetWorkspacesToLinkTo(false);

               SPWeb meetingWeb = null;
               foreach (SPWeb meetingWorkspace in meetingWorkspaces)
               {
               if (workspaceURL.Url.Contains(meetingWorkspace.Url))
               {
                   meetingWeb = meetingWorkspace;
                   break;
               }
               }

               SPList agendaList = meetingWeb.Lists["Agenda"];
               SPListItem newAgenda = agendaList.AddItem();
               boardWeb.EnsureUser(sponsor.LoginName);
               SPUser user = boardWeb.AllUsers[sponsor.LoginName];
               newAgenda["Sponsor"] = user;
               newAgenda["Subject"] = agendaTitle;
               newAgenda["AgendaID"] = agendaID;
               newAgenda["Owner"] = presenterName;
               newAgenda["Item Number"] = agendaOrder;
               newAgenda.Update();
        }
开发者ID:kawalgrover,项目名称:MARTA-Projects,代码行数:28,代码来源:BoardAgendaReceiver.cs

示例3: GetUsers

 public static IEnumerable<SPUser> GetUsers(this PeopleEditor peopleEditor, SPWeb web)
 {
     foreach (PickerEntity pickerEntity in peopleEditor.ResolvedEntities)
     {
         if (IsEntityUser(pickerEntity))
         {
             SPUser user = web.EnsureUser(pickerEntity.Description);
             yield return user;
         }
     }
 }
开发者ID:ricardocarneiro,项目名称:sharepoint-3,代码行数:11,代码来源:PeopleEditorExtensions.cs

示例4: GetUsersOrGroups

        public static IEnumerable<SPPrincipal> GetUsersOrGroups(this PeopleEditor peopleEditor, SPWeb web)
        {
            foreach (PickerEntity pickerEntity in peopleEditor.ResolvedEntities)
            {
                if (IsEntityUser(pickerEntity))
                {
                    SPUser user = web.EnsureUser(pickerEntity.Description);
                    yield return user;
                }
                else
                {
                    SPGroup group = web.SiteGroups.GetByName(pickerEntity.Description);

                    if (group != null)
                    {
                        yield return group;
                    }
                }
            }
        }
开发者ID:ricardocarneiro,项目名称:sharepoint-3,代码行数:20,代码来源:PeopleEditorExtensions.cs

示例5: FindUserOrSiteGroup

        public static SPPrincipal FindUserOrSiteGroup(SPWeb web, string userOrGroup)
        {
            SPPrincipal principal = null;
            if (SPUtility.IsLoginValid(web.Site, userOrGroup))
            {
                principal = web.EnsureUser(userOrGroup);
            }
            else
            {
                foreach (SPGroup group in web.SiteGroups)
                {
                    if (group.Name.ToUpper(CultureInfo.InvariantCulture) == userOrGroup.ToUpper(CultureInfo.InvariantCulture))
                    {
                        principal = group;
                        break;
                    }
                }
            }

            return principal;
        }
开发者ID:porter1130,项目名称:Analogic,代码行数:21,代码来源:MOSSPrincipal.cs

示例6: getUserRoles

        /// <summary>
        /// Gets selected User roles.
        /// </summary>
        /// <param name="strUser">User login.</param>
        /// <param name="web">Web.</param>
        /// <param name="strField">Field of the user to find.</param>
        /// <returns>ul structure with all the information.</returns>
        private string getUserRoles(string strUser, SPWeb web, string strField)
        {
            String strGroups = string.Empty;
            try
            {
                SPUser spUser = web.EnsureUser(strUser);
                XDocument usersInfoXml = XDocument.Parse(spUser.Groups.Xml);

                if (usersInfoXml.Descendants("Group").Count() > 0)
                {
                    var query = from userInfo in usersInfoXml.Descendants("Group")
                                select new
                                {
                                    fieldValue = userInfo.Attribute(strField).Value
                                };
                    strGroups = "<ul>";
                    foreach (var info in query)
                    {
                        strGroups += string.Format("<li>{0}</li>", info.fieldValue);
                    }
                    strGroups += "</ul>";
                }
                else
                {
                    strGroups = "-------";
                }

                return Context.Server.HtmlDecode(strGroups);
            }
            catch (Exception ex)
            {
                
                throw;
                //return "-------";
            }
        }
开发者ID:hmendezm,项目名称:SP.GlobalTopMenuAndFooter,代码行数:43,代码来源:ucSettings.ascx.cs

示例7: IsUserAnAdmin

        public static bool IsUserAnAdmin(SPWeb web)
        {
            SPUser user = web.CurrentUser;
            SPGroup group = null;

            try { group = web.SiteGroups[Util.Brightcove_AdministratorsGroup]; } catch {}

            if (group == null)
            {
                try
                {
                    SPUser ownerUser = user;
                    SPUser defaultUser = null;
                    web.EnsureUser(user.LoginName);
                    web.AllowUnsafeUpdates = true;
                    web.SiteGroups.Add(Util.Brightcove_AdministratorsGroup, web.SiteAdministrators[0], defaultUser, "Brightcove Video Cloud account administrators group");
                    group = web.SiteGroups[Util.Brightcove_AdministratorsGroup];
                    group.AddUser(web.SiteAdministrators[0]);
                    web.Update();
                    web.AllowUnsafeUpdates = false;

                    return true;
                }
                catch (SPException e)
                {
                    // Do nothing
                }
            }
            else
            {
                try
                {
                    if (user.Groups[Util.Brightcove_AdministratorsGroup].Name.Equals(group.Name))
                    {
                        return true;
                    }
                } catch {}
            }

            return false;
        }
开发者ID:BrightcoveOS,项目名称:Video-Cloud-SharePoint-2010-Integration,代码行数:41,代码来源:Util.cs

示例8: GetPrincipal

        /// <summary>
        /// Gets the principal.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <param name="loginName">Name of the login.</param>
        /// <returns></returns>
        internal static SPPrincipal GetPrincipal(SPWeb web, string memberName, string loginName)
        {
            foreach (SPPrincipal p in web.SiteUsers)
            {
                if (p.Name.ToLowerInvariant() == memberName.ToLowerInvariant())
                    return p;
            }
            foreach (SPPrincipal p in web.SiteGroups)
            {
                if (p.Name.ToLowerInvariant() == memberName.ToLowerInvariant())
                    return p;
            }

            try
            {
                SPPrincipal principal;
                if (!string.IsNullOrEmpty(loginName) && Microsoft.SharePoint.Utilities.SPUtility.IsLoginValid(web.Site, loginName))
                {
                    // We have a user
                    Logger.Write("Progress: Adding user '{0}' to site.", loginName);
                    principal = web.EnsureUser(loginName);
                }
                else
                {
                    // We have a group

                    SPGroup groupToAdd = null;
                    try
                    {
                        groupToAdd = web.SiteGroups[memberName];
                    }
                    catch (SPException)
                    {
                    }
                    if (groupToAdd != null)
                    {
                        // The group exists, so get it
                        principal = groupToAdd;
                    }
                    else
                    {
                        // The group didn't exist so we need to create it:
                        //  Create it:
                        Logger.Write("Progress: Adding group '{0}' to site.", memberName);
                        web.SiteGroups.Add(memberName, web.Site.Owner, web.Site.Owner, string.Empty);
                        //  Get it:
                        principal = web.SiteGroups[memberName];
                    }
                }
                return principal;
            }
            catch (Exception ex)
            {
                Logger.Write("WARNING: Unable to add member to site: {0}\r\n{1}", memberName, Utilities.FormatException(ex));
            }
            return null;
        }
开发者ID:GSoft-SharePoint,项目名称:PowerShell-SPCmdlets,代码行数:64,代码来源:ImportListSecurity.cs

示例9: EnsureOwnerUser

 protected virtual SPUser EnsureOwnerUser(SPWeb web, SecurityGroupDefinition groupModel)
 {
     if (string.IsNullOrEmpty(groupModel.Owner))
     {
         return web.Site.Owner;
     }
     else
     {
         return web.EnsureUser(groupModel.Owner);
     }
 }
开发者ID:nklychnikov,项目名称:spmeta2,代码行数:11,代码来源:SecurityGroupModelHandler.cs

示例10: EnsureDefaultUser

 protected virtual SPUser EnsureDefaultUser(SPWeb web, SecurityGroupDefinition groupModel)
 {
     if (string.IsNullOrEmpty(groupModel.DefaultUser))
     {
         return null;
     }
     else
     {
         return web.EnsureUser(groupModel.DefaultUser);
     }
 }
开发者ID:nklychnikov,项目名称:spmeta2,代码行数:11,代码来源:SecurityGroupModelHandler.cs

示例11: SetListPermission

        private void SetListPermission(SPWeb web)
        {
            var authenticatedUser = web.EnsureUser("NT Authority\\Authenticated Users");
            SPGroup reservationAdminGroup = web.Groups["Beach Camp General Supervisor"];

            var beachCampCalendar = Utility.GetListFromURL(Constants.BEACH_CAMP_CALENDAR_LIST_URL, web);
            if (beachCampCalendar != null && !beachCampCalendar.HasUniqueRoleAssignments)
            {
                beachCampCalendar.BreakRoleInheritance(false);
                beachCampCalendar.SetPermissions(authenticatedUser, SPRoleType.Contributor);
                beachCampCalendar.SetPermissions(reservationAdminGroup, SPRoleType.Contributor);
            }

            var beachCampPrice = Utility.GetListFromURL(Constants.BEACH_CAMP_PRICE_LIST_URL, web);
            if (beachCampPrice != null && !beachCampPrice.HasUniqueRoleAssignments)
            {
                beachCampPrice.BreakRoleInheritance(false);
                beachCampPrice.SetPermissions(authenticatedUser, SPRoleType.Reader);
                beachCampPrice.SetPermissions(reservationAdminGroup, SPRoleType.Contributor);
            }

            var beachCampTask = Utility.GetListFromURL(Constants.BEACH_CAMP_TASK_LIST_URL, web);
            if (beachCampTask != null && !beachCampTask.HasUniqueRoleAssignments)
            {
                beachCampTask.BreakRoleInheritance(false);
                beachCampTask.SetPermissions(reservationAdminGroup, SPRoleType.Contributor);
                beachCampTask.SetPermissions(authenticatedUser, SPRoleType.Reader);
            }
        }
开发者ID:dangquocthai,项目名称:beachcamp,代码行数:29,代码来源:SharePoint.EventReceiver.cs

示例12: EnsureOwnerUser

        protected virtual SPPrincipal EnsureOwnerUser(SPWeb web, string owner)
        {
            if (string.IsNullOrEmpty(owner))
            {
                return web.Site.Owner;
            }
            else
            {
                bool max;

                var principalInfos = SPUtility.SearchPrincipals(web, owner, SPPrincipalType.All, SPPrincipalSource.All, null, 2, out max);

                if (principalInfos.Count > 0)
                //if (principalInfos.Value != null)
                {
                    var info = principalInfos[0];

                    if (info.PrincipalType == SPPrincipalType.User || info.PrincipalType == SPPrincipalType.SecurityGroup)
                        return web.EnsureUser(info.LoginName);

                    if (info.PrincipalType == SPPrincipalType.SharePointGroup)
                        return web.SiteGroups.GetByID(info.PrincipalId);
                }

                throw new SPMeta2Exception(string.Format("Cannot resolve Principal by string value: [{0}]", owner));
            }
        }
开发者ID:ReneHezser,项目名称:spmeta2,代码行数:27,代码来源:SecurityGroupModelHandler.cs

示例13: GetSPFieldUserValue

        internal static void GetSPFieldUserValue(SPWeb web)
        {
            SPList list = web.Lists[SPListName.TravelExpenseClaim];

            foreach (SPListItem item in list.Items)
            {
                string ss = string.Empty;
                SPUser user = web.EnsureUser(item["ApplicantSPUser"].ToString().Split(new string[] { ";#" }, StringSplitOptions.None)[1]);
                Console.WriteLine(item["ApplicantSPUser"].ToString());
            }
        }
开发者ID:porter1130,项目名称:MyTest,代码行数:11,代码来源:SharePointEntry.cs

示例14: SetRootSitePermissions

        private void SetRootSitePermissions(SPWeb web)
        {
            try
            {
                string groupOwners = web.Title.Trim() + " Owners";
                web.CreateNewGroup(groupOwners, "Use this group to grant people full control permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Administrator);

                string groupMembers = web.Title.Trim() + " Members";
                web.CreateNewGroup(groupMembers, "Use this group to grant people contribute permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Contributor);

                string groupVisitors = web.Title.Trim() + " Visitors";
                web.CreateNewGroup(groupVisitors, "Use this group to grant people read permissions to the SharePoint site: " + web.Title.Trim(), SPRoleType.Reader);

                web.Update();

                Utility.ChangeSPGroupOwnerBySPGroup(web, groupOwners, groupOwners);
                Utility.ChangeSPGroupOwnerBySPGroup(web, groupMembers, groupOwners);
                Utility.ChangeSPGroupOwnerBySPGroup(web, groupVisitors, groupOwners);

                SPUser authenUsers = web.EnsureUser("NT AUTHORITY\\authenticated users");
                if (authenUsers != null)
                {
                    SPGroup spGrp = web.Groups[groupVisitors];
                    if (spGrp != null)
                    {
                        spGrp.AddUser(authenUsers);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message, AIAPortalFeatures.Infrastructure);
            }
        }
开发者ID:chutinhha,项目名称:aiaintranet,代码行数:34,代码来源:AIA.Intranet.Infrastructure.Site.EventReceiver.cs

示例15: GetUserSharePointGroups

 /// <summary>
 /// Get user SharePoint groups membership (bypass AD groups in SharePoint groups)
 /// </summary>
 /// <param name="web">The web.</param>
 /// <param name="userName">The user name.</param>
 /// <returns>List of groups.</returns>
 public ICollection<string> GetUserSharePointGroups(SPWeb web, string userName)
 {
     return (from SPGroup @group in web.Groups let isMember = this.IsUserInGroup(web.EnsureUser(userName), @group) where isMember select @group.Name).ToList();
 }
开发者ID:andresglx,项目名称:Dynamite,代码行数:10,代码来源:UserHelper.cs


注:本文中的SPWeb.EnsureUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。