Popular Posts
DataList paging //利用PageDataSource來做分頁功能 PagedDataSource pds = new PagedDataSource(); //將PageDataSource綁定SqlDataSource pds.DataSource = SqlDataSource1.Selec... Grant permission for virtualbox shared folder The regular way of getting access to the files now, is to allow VirtualBox to automount the shared folder (which will make it show up under ... Asynchronous and deferred JavaScript execution explained Normal execution <script> This is the default behavior of the <script> element. Parsing of the HTML code pauses while the scr...
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();
    }
}