views:

47

answers:

2

I am looking at ways of limiting data (pages) visible to users based on their SharePoint group memberships. One option is to run my site on it's own, determine group membership in code, and limit data available, and the other, less attractive option is to deploy my site to several departmental sites, and then determine which data to present according to the parent site that mine is hosted under.

In either case, I need to access some sort of SharePoint API to determine either the location of my site, or the group membership of the logged on user. How can I go about getting this information?

A: 

You don't need to do anything in code. Based on your description, you are trying to limit access to data on pages, based on their membership of a particular SharePoint group. Break the inheritance from the main site and just configure access for those in that SharePoint group...

IrishChieftain
I don't want to duplicate e.g. the report, once per department. I just want one report page where I use a department parameter.
ProfK
A: 

You could use a Web Part and programmatically security trim links in the WP. In any case, Groups are created at the site collection level and assigned to a site. If you have a site located at mycompany/mydeptsite, you could use:

SPSite siteCollection = new SPSite("http://mycompany/mydeptsite");
SPWeb site = siteCollection.OpenWeb();

foreach(SPGroup group in site.Groups)
{
    Console.WriteLine(group.Name);
}

Some more info: http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/

IrishChieftain