Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. SharePoint
  4. Some trouble with creating a group on feature activation

Some trouble with creating a group on feature activation

Scheduled Pinned Locked Moved SharePoint
announcementcsharpsharepointvisual-studiodebugging
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aptiva Dave
    wrote on last edited by
    #1

    I've built a feature for our training department, which up until today has worked as intended. Today wrote some code in the feature activation that will add a new SharePoint group called 'Travel Plaza Managers' (Travel Plaza is a department within our organization that runs our gas stations). On the feature activation I first run a function called 'checkForGroup', which checks to see if the group has already been created on the site. Here is the code for that group:

    ''' ''' Checks to see if the group exists in the the site
    '''
    '''
    '''
    '''
    Public Function checkForGroup(ByVal groupName As String, ByVal web As SPWeb) As Boolean
    Dim group As SPGroup = Nothing
    Try
    group = web.Groups(groupName)
    Catch ex As Exception

        End Try
    
        If Not group Is Nothing Then
            Return True
        Else
            Return False
        End If
    End Function
    

    If this function returns 'False' then I call another function called 'CreateTPManagersGroup', which runs this code:

    ''' ''' Creates the Travel Plaza Managers Group
    '''
    ''' The current web
    '''
    Public Sub CreateTPManagersGroup(ByVal web As SPWeb)
    'create the owner of the group
    Dim owner As SPUser = web.SiteAdministrators("username")
    Dim member As SPMember = web.SiteAdministrators("username")
    'get the groups
    Dim groups As SPGroupCollection = web.SiteGroups
    'add the Travel Plaza Managers to the list of site groups
    groups.Add("TP Managers", member, owner, "These are the current Travel Plaza Managers of the Choctaw Nation")
    Dim newSPGroup As SPGroup = groups("TP Managers")
    Dim role As SPRoleDefinition = web.RoleDefinitions("Read")
    Dim roleAssignment As SPRoleAssignment = New SPRoleAssignment(newSPGroup)
    roleAssignment.RoleDefinitionBindings.Add(role)
    web.Update()
    End Sub

    So, the first time I ran this, the activation ran fine, but when I went to see if the group had been created the group name wasn't there. Figured I may have done something like not actually deploy the current version of the feature, so I did another deploy from Visual Studio and got the message saying that the group name had already been used. Did a debug on th

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups