Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

To put this in context, what I need to do to complete work on a custom action is to hide a particular column from users who aren't members of a given group. Given that the custom action is implemented with C# code, I'm looking for a tidy way to do this programmatically.

For a brief moment, it looked like a single line of code would do the trick:

SPContext.Current.List.DefaultView.ViewFields.Delete("Name Of Column I Want To Hide");

Even though the view seems to change internally, this statement seems to have no effect.

There are a few available examples that use ViewFields.Delete, but they're all followed by calls to ViewFields.Update() - in other words, they presume that you want to permanently remove the column. But I just want to remove it for the current context.

Can anyone here enlighten me as to what tactic might work in this case?

Thanks in advance Josh

share|improve this question
    
With more research, I learned that rendering of the view is done long before my control is initialized, and it doesn't look like there's any way of adding an event to the list view that would allow me to do this. So I had to use a less elegant approach (see below) –  Josh Korn Jul 14 '11 at 14:27
add comment

2 Answers 2

WIth the standard controls, it's not possible to put authorization on viewing/editing on a field. The smallest scope is per listitem.

I don't know if this would be an option:

  • create two listviews and put them on your page, both with an audience on it: one for group 1, one for the others.

this is no security, but this way you are hiding that one column for that one specific audience.

share|improve this answer
    
Bas, I ended up with two views, one with this field (and an Edit button), the other without. I used jQuery to hide the magic view from most users (in my particular environment, I already hide several items and views from users who don't have a Site Actions menu). Thanks –  Josh Korn Jul 14 '11 at 14:25
add comment

You can accomplish this without coding using SharePoint Forms Designer, it allow to display or hide specified fields on forms just by dragging and dropping it, you also can create forms with different fields displayed for specified SharePoint group.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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