title: Rewriting site permissions in Sharepoint / c#
body: <p>I'm trying to copy site permissions from one site to another. When I was trying to copy permissions from site which has 6 users added it worked fine, but then I run my code to copy permissions from site with 87 users - result was unexpected. All users were rewriten correctly but many of permissions was wrong (like Web-Admins having View only). Anyone may know how to fix this? Thanks in advance!</p>
  
  <pre><code>//ealier here I clear all permissions from destSite (it works fine)
  clientContext.Load(sourceSite.RoleAssignments);
  clientContext.ExecuteQuery();
  for (int i = 0; i &lt; sourceSite.RoleAssignments.Count; i++)//scource -&gt; dest copy
  //foreach (RoleAssignment role in sourceSite.RoleAssignments)
  {
       SPSecurity.RunWithElevatedPrivileges(delegate()
       {
            RoleAssignment role = sourceSite.RoleAssignments[i];
  
            clientContext.Load(role, r =&gt; r.Member, r =&gt; r.RoleDefinitionBindings);
            clientContext.ExecuteQuery();
  
            destSite.RoleAssignments.Add(role.Member, role.RoleDefinitionBindings);
            premCoppied++;
       });
  
  }
  </code></pre>