Sharepoint 2007/2010 hiding list or library items (i.e. rows)

sharepointsharepoint-2007sharepoint-2010sharepoint-apisharepoint-designer

I wanted to know if there's a way to hide list or library row items based on the content of a specific column.

Here is a use case scenario:

I have a list or library of any kind, I have a column called Permissions, within that column I can specify one of two group name types as strings, e.g "Owners" or "Visitors". Afterword, I have conditions that go through each individual row item in the list or library and base the visibility of that row item on the string content of the Permissions column.

Row Visibility Logic Pseudo:

If( current_row.Permissions_Col.Content == LoggedInUser.Group_Name)
 Show this row
Else
 Hide this row

Is it possible do accomplish this either through the Sharepoint web interface or programmitcally in Sharepoint Designer or Visual Studio?? Insight is appreciated.

UPDATE:

Thanks all for the feedback, just to clarify the motivation for this is our document structure and security/permissions layer is very dynamic, so we can't create a static hierarchy in SharePoint. Instead we want to have one single library pool of resources which are filtered on the fly based on the Group membership of the currently logged in user. We want to treat the Permissions column content as metadata to describe who can view this row's data.

My apologies, but another requirement I neglected to mention is that when the logged-in user tries to upload a file or create a new element (i.e. List, Library, Folder, Form, etc.) in SharePoint, permissions get set automatically for the user's group and for "Owners". The only exceptions to this condition would be "Owners". So the pseudo is something like this:

File Upload / Item Creation Logic:

If( (creatingElement OR uploadingFile) AND LoggedInUser.Group_Name != "Owners")
{
  SET Permissions_Col.Content to LoggedInUser.Group_Name; 
  SET read permissions for LoggedInUser.Group_Name and full control for "Owners";
}

Best Answer

Solution here depends on the purpouse of your action. If there is no business impact when a visitor accesses an item which is marked "Owners", you can go for filtering. This is the case when you could use "audience" feature of Sharepoint, as Nat is advising in his answer. Bear in mind, though, that a Visitor may open your list in a different view (or in Ms Excel, for instance) and see all items in your list.

However, if the rows marked as "Owners" should only be seen by the owners of your system, you have to think of actually assigning permissions to the list items. There are two ways I could think of:

  • separate the items in two folders, assign different permissions to the folders. Then use a recursive view to list all the items in a single list
  • use item level permissions. If you choose this path, you would have to write an asynchronous event handler (on ItemUpdated) to check the value of "permissions" field and set appropriate permissions.
Related Topic