none
Sharepoint list access programmatically RRS feed

  • Question

  • Please tell me how to make list level access work with respect to a particular user in sharepoint programmatically? If possible using form based sharepoint authentication.

    Thanks a million in advance.
    • Moved by Mike Walsh FIN Tuesday, April 14, 2009 2:47 PM programmatically
    Tuesday, April 14, 2009 2:43 PM

Answers

  • itsaliakber> Mike moves the thread that are out of place to the correct fora, like he also did to this post (General > Development)


    More on topic:

    SPList has SPRoleAssignments (Which are not more that bindings to the SPPrincipal (Which is a User or a Group))
    Each SPRoleAssignment can have multiple SPRoleDefinitions (Rights, like "Reader" or "Contributer")

    To put this in a sample:

    foreach(SPRoleAssignment oRA in myList.RoleAssignments) {
     // oRA.Member contains what User these rights are bound to
     foreach(SPRoleDefinition oRD in oRA.RoleDefinitionBindings) {
      // Each oRD is a roledefinition like Reader or Contributor

     }
      // To add a roleDefinition like reader, simply do
      // oRA.RoleDefinitionBindings.Add(SPContext.Current.Web.RoleDefenitions.GetByType(SPRoleType.Reader));
    }
      // To add a roleAssignment like company\username, simply do
      // myList.RoleAssignments.Add(new SPRoleDefinition("company\\username", "", "", ""));
      // myList.Update();


    I hope this answers your question.

    Regards,
    Jeroen
    My blog on WSS / MOSS development is found at http://jebass.blogspot.com
    • Marked as answer by itsaliakber Tuesday, April 21, 2009 11:10 AM
    Tuesday, April 14, 2009 3:38 PM

All replies

  • When will you guys learn?  (I get at least one here in General most days)

    If you have a "programmatically" issue, it goes in the Programming forum. It's surely not that difficult.

    Moving this.
    WSS FAQ sites: WSS 2.0: http://wssv2faq.mindsharp.com WSS 3.0 and MOSS 2007: http://wssv3faq.mindsharp.com
    Total list of WSS 3.0 and MOSS 2007 Books (including foreign language titles) http://wssv3faq.mindsharp.com/Lists/v3%20WSS%20FAQ/V%20Books.aspx
    Tuesday, April 14, 2009 2:47 PM
  • Mike,

             I guess its a sharepoint dev. and programming forum and my question is within context. Help me if im wrong.
    Tuesday, April 14, 2009 3:27 PM
  • itsaliakber> Mike moves the thread that are out of place to the correct fora, like he also did to this post (General > Development)


    More on topic:

    SPList has SPRoleAssignments (Which are not more that bindings to the SPPrincipal (Which is a User or a Group))
    Each SPRoleAssignment can have multiple SPRoleDefinitions (Rights, like "Reader" or "Contributer")

    To put this in a sample:

    foreach(SPRoleAssignment oRA in myList.RoleAssignments) {
     // oRA.Member contains what User these rights are bound to
     foreach(SPRoleDefinition oRD in oRA.RoleDefinitionBindings) {
      // Each oRD is a roledefinition like Reader or Contributor

     }
      // To add a roleDefinition like reader, simply do
      // oRA.RoleDefinitionBindings.Add(SPContext.Current.Web.RoleDefenitions.GetByType(SPRoleType.Reader));
    }
      // To add a roleAssignment like company\username, simply do
      // myList.RoleAssignments.Add(new SPRoleDefinition("company\\username", "", "", ""));
      // myList.Update();


    I hope this answers your question.

    Regards,
    Jeroen
    My blog on WSS / MOSS development is found at http://jebass.blogspot.com
    • Marked as answer by itsaliakber Tuesday, April 21, 2009 11:10 AM
    Tuesday, April 14, 2009 3:38 PM
  • Thanks a lot jeroen, As i am dynamically creating a list and trying to assign it to a user how will i achieve this using form based authenticatino in sharepoint.

    Please help me in this regard.


    Tuesday, April 14, 2009 4:06 PM
  • What do you need exactly? I don't think the fact that you are using FBA changes the logic very much.
    You can still use the SPRoleAssignments with their SPRoleDefinitions like when using SSO.

    Jeroen
    My blog on WSS / MOSS development is found at http://jebass.blogspot.com
    Tuesday, April 14, 2009 4:12 PM