Popular Posts
Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... CTE, recursive search WITH DepartmentSearch(DeptID, DeptParent, DeptName, OuID) AS (     -- 找出簽核者所屬部門     SELECT d.DeptID, d.DeptParent, d.DeptName, d.OuID     FR... Create web service client cross SSL with eclipse When creating web service cross SSL using eclipse, it occuss some error like below: And it can't build the client source from this wa...
Stats
Group operation: create, grant permission and add member using client object model
public void Main(string[] args)
{
    var siteCollectionUrl = "http://your_site_url";
    var member = "domain\\account";

    using (var ctx = new ClientContext(siteCollectionUrl))
    {
        var web = ctx.Web;
        ctx.Load(web, w => w.ServerRelativeUrl);
        ctx.ExecuteQuery();

        // Create a new group named 'Contact'
        var groupInfo = new GroupCreationInformation();
        groupInfo.Title = "Contact";
        groupInfo.Description = string.Format(@"Use this group to grant people full control permissions to the SharePoint site: {0}", groupInfo.Title);
        var group = web.SiteGroups.Add(groupInfo);
        ctx.Load(group);
        ctx.ExecuteQuery();

        // Set group properties
        group.OnlyAllowMembersViewMembership = false;
        group.AllowMembersEditMembership = true;
        group.Update();
        ctx.ExecuteQuery();

        // Grant group permission
        var fullControlPermission = web.RoleDefinitions.GetByName("Full Control");
        var roleBinding = new RoleDefinitionBindingCollection(ctx);
        roleBinding.Add(fullControlPermission);
        web.RoleAssignments.Add(group, roleBinding);
        ctx.ExecuteQuery();

        // Add new member to group
        var u = web.EnsureUser(member);
        ctx.Load(u);
        ctx.ExecuteQuery();
        var userInfo = new UserCreationInformation();
        userInfo.Email = u.Email;
        userInfo.Title = u.Title;
        userInfo.LoginName = u.LoginName;
        group.Users.Add(userInfo);
        ctx.ExecuteQuery();
    }
}