SharePoint C# Get list of sites on which user has permission (Read, Contribute, Owner, Admin, Visitor)

HI,
I wants to get list of sites on which user has permission, all permission name like (read, visitor, contribute, owner)
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
foreach (SPWeb oWeb in oSite.RootWeb.GetSubwebsForCurrentUser())
permission = string.Empty;
foreach (SPGroup group in oWeb.Groups)
foreach (SPUser u in group.Users)
if (u.Name == (userName))
foreach (SPRole role in u.Roles)
permission += role.Name.ToString() + ", ";
} // Taking All Permission details of user
permission = " [" + permission.TrimEnd(", ".ToCharArray()) + "]";
my final string variable will have values like [Read, Visitor] or [Read] or [visitor, Read]
I wants to have all permission names and also geting error on u.Roles [Roles is absolute now],
 Help me to get permission by using SPRoleDefination etc
SPRoleDefinitionCollectionroleDefinitions
= oWeb.RoleDefinitions;
SPRoleDefinitionroleDefinition
foreach(SPRoleAssignmentroleAssigment
inoWeb.RoleAssignments)
 Thanks
Praveen

Depending on how large your farm is and how many webapplications / site collections you need to enumerate to build this list, you might be better off using search to get the list of sites/webs that the user has access to (search results are security trimmed).
You could then enumerate just the list of sites returned to determine the exact permissions.
E.g. Code for getting a list of sites the user has access to:
var ssaProxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));
var keywordQuery = new KeywordQuery(ssaProxy);
keywordQuery.RowLimit = 200;
keywordQuery.SelectProperties.Clear();
keywordQuery.SelectProperties.Add("Title");
keywordQuery.SelectProperties.Add("Url");
keywordQuery.ResultsProvider = SearchProvider.Default;
keywordQuery.QueryText = String.Format("contentclass:STS_Site OR contentclass:STS_Web");
keywordQuery.ResultTypes |= ResultType.RelevantResults;
ResultTableCollection searchResults;
searchResults = keywordQuery.Execute();
if (searchResults.Exists(ResultType.RelevantResults))
var searchResult = searchResults[ResultType.RelevantResults];
var results = new DataTable { TableName = "SearchResults" };
results.Load(searchResult, LoadOption.OverwriteChanges);
if (results.Rows.Count > 0)
var resultsText = new StringBuilder();
foreach (DataRow dataRow in results.Rows)
var urlToWeb = dataRow["Url"] as String;
//Perform your checking to determine the exact permissions
Regards, Matthew
MCPD | MCITP
My Blog
Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.
I just added a webpart to the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
Upload and Crop User Profile Photos

Similar Messages

  • Maxl/esscmd to get list of applications/databases that user has access to

    Is there any maxl/esscmd to get the list of applications/databases that a user has access to?
    I know that LISTGROUPUSERS 'groupName' -- this list all users of a group.
    Can anyone help please?

    MaxL
    display privilege user SomeUser;

  • How to determine which user has an Access 2013 databse open

    How can I tell which user / PC has opened a Backend Access database?

    If the file is stored on a server and you have access to it, you could check in Computer Management, then go into System Tools, Shared Folders, Open Files, and you should find the file listed there along with which user has it open currently.

  • How to get list of applied patches which applied using admrgpch

    How to get list of applied patches which applied using admrgpch

    You can't really get the individual patch IDs from a merged patch, unless you have the log file from the admrgpch run available.
    You can, however, get the list of bugs fixed by a merged patch, and those bug numbers sometimes, but not always, correspond to a patch ID. Keep in mind, though, that individual patches often contain entries for multiple bug numbers.
    Here's a query that I use to look at the contents of merged patches. It works best if the merged patches have been given unique names, instead of the default name 'merged' from admrgpch. If you run it and see that everything belongs to patch name 'merged,' you might want to change the selected column to ap.applied_patch_id instead of ap.patch_name.
    select ap.patch_name
    , ad.orig_patch_name
    , ad.driver_file_name
    , ad.merged_driver_flag
    , ad.merge_date
    , bug.bug_number
    , cp.patch_abstract
    from ad_applied_patches ap
    join ad_patch_drivers ad using (applied_patch_id)
    join ad_comprising_patches cp using (patch_driver_id)
    join ad_bugs bug using (bug_id)
    order by applied_patch_id;
    Regards,
    John P.
    http://only4left.jpiwowar.com

  • Which user has what permissions in AD

    Greeting Folks
    , is there a way to find out which user has what permissions in the entire domain? Are there any tools / software
     that can be leveraged to get such information.

    Hi,
    Based on my knowledge, you need to use PFDavAdmin Tool to open mailboxes and verify the folder permission of calendar on Exchange 2007. Since the Get-MailboxFolderPermission cmdlet is unavailable for Exchange 2007.
    In Exchange 2010, the most suitable command should be "MailboxFolderPermission" for calendar permission. If you would like to check the permissions that user2 has to view user1's calendar, you can use the following cmdlet:
    Get-MailboxFolderPermission -Identity "User1:\Calendar" -User User2
    What's more, you can use the Get-Mailbox | Get-MailboxfolderPermission cmdlet to query the permissions of all the folders.
    Get-Mailbox | Get-MailboxfolderPermission
    Hope it helps.
    Best regards,
    Amy
    Amy Wang
    TechNet Community Support

  • Which user has which authorizations

    Hi all,
    I need to know which user has which authorizations.
    In which tables can I find these data?
    Thanks.
    deniz.

    Hi,
        Check this .
    USR01 contains the runtime data of the user master records
    USR02 is the table containing logon information such as the password
    USR03 includes the users' address information
    USR04 contains users' authorizations
    USR05 is the users' parameter ID table
    USR09 contains user menus
    USR10 is the table for user authorization profiles
    USR11 contains the descriptive texts for profiles
    USR12 is the user master authorization values table
    USR13 contains the descriptive short texts for authorizations
    USR14 contains the logon language versions per user
    USR30 includes additional information for user menus
    USH02, USH04, USH10 and USH12 contains Users and profile and
    authorization change history data.
    Tables related with authorizations objects and authorization fields are as follows:
    TOBJ is the authorization objects table containing the authorization
    fields for each.
    TACT contains the list of standard activities authorization fields
    in the system.
    TACTZ is the table which defines the relationship between the
    authorization objects and the activities in those objects containing
    the Activity authorization field.
    TSTC is the transaction code table where authorization objects
    and values can be defined.

  • Is it possible to determine which user has opened a PDF on a network?

    Hi Everyone.
    We frequently have a situation where users open PDFs saved on the network with Acrobat, and then leave them open.
    Then if other users need to edit the same PDF, they have no way of knowing the PDF is locked until they try to save and get this error:
    "...The file may be read-only or another user may have it open... "
    In this situation it would be useful to be able to interrogate the locked PDF to see which user has locked it open, and maybe to even force close the open session.
    Does anyone know if any of this is possible?
    Many thanks in advance.
    Cheers,
    Andy

    It's not something that Acrobat can show. File 'locks' in Acrobat are not controlled by the application as they are in programs such as Word or InDesign - which write a lockfile to the folder - instead we rely on the server OS to flag each file. Information on who is accessing a file on a network share is only available at operating system level via the machine which hosts the share (e.g. via a net session command).

  • How to find out which user has locked a particular record of a table

    Hi
    Is it possible to know - which user has locked a particular record (I know the primary key of the record) of a table
    Regards

    select     OS_USER_NAME os_user,
         PROCESS os_pid,
         ORACLE_USERNAME oracle_user,
         l.SID oracle_id,
         decode(TYPE,
              'MR', 'Media Recovery',
              'RT', 'Redo Thread',
              'UN', 'User Name',
              'TX', 'Transaction',
              'TM', 'DML',
              'UL', 'PL/SQL User Lock',
              'DX', 'Distributed Xaction',
              'CF', 'Control File',
              'IS', 'Instance State',
              'FS', 'File Set',
              'IR', 'Instance Recovery',
              'ST', 'Disk Space Transaction',
              'TS', 'Temp Segment',
              'IV', 'Library Cache Invalidation',
              'LS', 'Log Start or Switch',
              'RW', 'Row Wait',
              'SQ', 'Sequence Number',
              'TE', 'Extend Table',
              'TT', 'Temp Table', type) lock_type,
         decode(LMODE,
              0, 'None',
              1, 'Null',
              2, 'Row-S (SS)',
              3, 'Row-X (SX)',
              4, 'Share',
              5, 'S/Row-X (SSX)',
              6, 'Exclusive', lmode) lock_held,
         decode(REQUEST,
              0, 'None',
              1, 'Null',
              2, 'Row-S (SS)',
              3, 'Row-X (SX)',
              4, 'Share',
              5, 'S/Row-X (SSX)',
              6, 'Exclusive', request) lock_requested,
         decode(BLOCK,
              0, 'Not Blocking',
              1, 'Blocking',
              2, 'Global', block) status,
         OWNER,
         OBJECT_NAME
    from     v$locked_object lo,
         dba_objects do,
         v$lock l
    where      lo.OBJECT_ID = do.OBJECT_ID
    AND l.SID = lo.SESSION_ID
    hope this helps
    Zekeriya

  • How to find out which user has the permission to execute startsap ?

    Hi All
    How do I find out which user has the permission to execute the startsap and stopsap? Do I control the permission on those script using windows standard authorization? For example: only allow certain user have the read and write permission?
    Thank you.!
    Vincent Lo

    Well to me this is really weird question..
    <b>noone un-authorized should have access to OS on your system</b>
    If this is valid you do not need to solve problems who can and who cannot start/stop SAP, because if you want to prevent some users from shutting down the SAP you have really hard job to do - there are many ways how to kill the SAP (for example killing relevant process from task manager, killing of database, messing with services etc.) - yes, this is harmful way of stopping SAP, but we are talking about attack, right? I would contact some Windows specialist to help you disable all the ways how to harm the running SAP. But still after that - there are many files that can be modified/deleted so SAP will crash after restart - you need to protect them too, etc.
    In case you take the first assumption as granted (and you really limit access to this server) you do not need to worry who can stop or start SAP - at the other hand it may be handy to be able to start/stop SAP from other users - for this you can run the stop/start script "under different user".
    But to answer the question - to me this is question just of access control (but really never tried that myself):
    <a href="http://technet2.microsoft.com/WindowsServer/en/library/c6413717-511e-42bd-bd81-82431afe4b2a1033.mspx">Permit or restrict access to a snap-in for a domain</a> (or see other related links down there on this page)
    Please award points for useful answers.
    Thanks

  • Find which user has "Personal Greeting"

    Dear NetPro gurus,
    Is there any tools that can help my customer to view at a glance which user has used Personal Greeting, and which are just using System Default greeting??
    One of my customers has over 1,000 users and I was wondering whether such tool exist rather than having me to click on each user mailbox one-by-one. 
    I did tried to export using Bulk Administration Tool as well as using User Dump Tool but neither allows me to see who has used Personal Greeting on their mailbox.
    I have spent a lot of time research on this already.  Would greatly appreciated if anyone can shed some light on this.
    Cheers,
    Hunt

    You had a previous post on this in which I provided the following:
    When you run the Subscriber  Information Dump for Unity, you have the option to pull the WAV file  info for greetings as well as data for which greeting(s) are enabled.   When you do that, you would be able to see the following:
    Greeting WAV file – standard. This will include the WAV file name of the standard greeting for a  subscriber. The WAV file itself is copied into      the same directory  where you select the CSV File to be written to so be sure to pick a  directory that has enough space to store all the greeting      files. The  file will be named with the alias of the subscriber followed by  “_GREETING_STANDARD.WAV”.   If there is no standard      greeting  recorded for the subscriber, the column will be empty. If  there is a standard greeting it will be copied to the output directory  as noted and the file name used will be written in the column.
    I  haven't looked at this data for the purpose you intend but the standard  (and alternate) greetings are the most commonly used.  When you set up  your mailbox, it asks you to record a personal greeting (this would be  the Standard greeting).  If you do not record a personal greeting then  the system default would be used.  So, if I have a personal greeting  then the applicable Greeting WAV file output in the subscriber dump  should be populated.  Otherwise, it would be blank.  Should be easy for  you to test and verify if this is the case.
    I think this will give you what you need.  Did you take a look at this data yet?
    Hailey
    Please rate helpful posts!

  • Help!!! How do I get the bit color depth the user has his screen set to?

    Help!!! How do I get the bit color depth the user has his screen set to?
    Thank you.

    i'm not sure if it's what you 're looking for but it worked for me:
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for(int i=0;i<gs.length;i++){ //length is 1 (= i have only one screen? )
    GraphicsDevice g=gs[ i ];
    int nBits=g.getDisplayMode().getBitDepth(); //method getDisplayMode() only in jdk1.4 , i think
    System.out.println( nBits+"");
    output is 32 if i set my screen color to 32bits, 24 if...24, ...

  • How to find which users has used external scripting

    I want to find out the users who used the scripting for doing any mass changes activity.

    Hi Murphy;
    Please check which user has which forms open? and Re: how to determine which forms are currently open?
    Hope it helps you in your issue
    Regard
    Helios

  • How to check which user has the privilege to execute a stored procedure?

    I am using Oracle 7 and I would like to check which user has the privilege to execute a stored procedure. How can I check it? Is there any view I can query for?
    Alex Hung

    Please check DBA_SYS_PRIVS.
    SQL> select * from dba_sys_privs
    2 where grantee='HARY';
    GRANTEE PRIVILEGE ADM
    HARY EXECUTE ANY PROCEDURE NO
    ....

  • Log to check as to which user has accessed which report?

    Hi,
    I am using BOBJ for report creation and SAP BI for datawarehousing.
    The user can access these reports using the iviews created in the portal. Due to some performance testing requirements we need to check which user accessed which report and if he has drilled down to a particular level in a report, then there should be a means to know that as well.
    BO offers a few standard activity reports to check which user has done which activity. However the details of drill down etc. cannot be checked using that. Please help as to how can we check that too.
    Best Regards,
    Neha

    Hi,
    See [Business Objects|/community [original link is broken]; and [Crystal Reports|/community [original link is broken]; forums for this topic.
    -Paul

  • What is the REST endpoint URL to get list of site collections in Sharepoint ?

    Hi,
    If I go to Sharepoint 2013 site, click on Admin -> Sharepoint, you will see a list of site collections (the link is https://somename-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx)
    What is the REST endpoint URL to retrieve this list of site collections ?
    I was trying _api/search/query?querytext='contentclass:sts_site' or _api/search/query?querytext='contentclass:sts_web', but it doesn't give the whole list...

    As far as i know, There is no REST endpoint at FARM level
    it would be good to see a possible way to do this.
    If my contribution helps you, please click Mark As Answer on that post and
    Vote as Helpful
    Thanks, ShankarSingh(MCP)

Maybe you are looking for

  • Can't hook my computer to my tv using HDMI cord anymore???

    tv searches but cant find my computer??? i use to just plug it in computer went dark and tv became my screen had full control but now nothing

  • Frame set problem

              Hi, all,           I wrote a program with multiple frames. The topist frame contains a menu1.jsp           page and a content1.jsp page. The content1.jsp page cotains another frame which           has a menu2.jsp page and content2.jsp page.

  • Embedding assembly in C code using V.S 2008

    Hello, I created a console application prject with V.S 2008 and copied the following code from MSDN: https://msdn.microsoft.com/en-us/library/5f7adz6y.aspx // asm_overview.cpp // processor: x86 void __declspec(naked) main() // Naked functions must pr

  • Airport Extreme just stopped working

    I have a airport extreme and and Airport Express. They have both been working on the same router for about a year or two. Now all of a sudden the Airport Extreme line doesnt work. I try to reconfigure and get the following message"Airport Utlity unab

  • Build and Alter Task_2 - Applying HCM 9 - MP4

    Hi ALL, its the job (3 of 3). After building and running the project HC9_ALTER4, following 3 scripts need to be run but these scripts failed: i am pasting the actual code from the scripts Script: BR688701_01.dms SET LOG BR688701_01.log; --UPDATE PS_G