0

I am having the Visual Webpart in VS2012 for SharePoint2010 site. On this webpart there is Publish button. I want to make visible and enabled to HR Group.What Permission I need to set for HR Group and for other users? Other user should not even see that button. What I have to do for this ?

I used following :

<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" PermissionsString="BrowseDirectories" runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly">
    <asp:Button ID="btnPublish" runat="server" Text="Publish Top 10" OnClick="btnPublish_Click" />
</SharePoint:SPSecurityTrimmedControl>

But all users able to see this button on Webpart after deployment.

2 Answers 2

1

You can do it by code also:

if (SPContext.Current.Web.CurrentUser.Groups.Cast<SPGroup>().Any(g => g.Name == "hr Group"))
 {
    show button
 }
 else
 {
    hide button
 }
1

SPGroup.ContainsCurrentUser() is also an option.

You can get the HR group as usual and check if the HR group contains the current user. Then, it's just about hide/disable that button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.