1

I understand that I can impersonate a user with a user's token to get their personal view, but is there a less brute way of getting personal views?

Is there an account I'm over-looking that has "super access" that would be able to return all personal views? Or is iterating through each user and impersonating the only option here?

0

You can use SPSecurity.RunWithElevatedPrivileges method for super access.

Executes the specified method with Full Control rights even if the user does not otherwise have Full Control.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

static void GetViews(SPSite site)
        {
            SPWeb spweb = site.OpenWeb();
            foreach(SPUser oUser in spweb.AllUsers)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    try
                    {
                        SPSite oElevSite = new SPSite(site.ID, oUser.UserToken);
                        SPWeb oElevWeb = oElevSite.RootWeb;
                        SPList splist = oElevWeb.Lists["CustomStatusList"];
                        SPViewCollection views = splist.Views;
                        foreach (SPView view in views)
                        {
                            if (view.PersonalView)
                            {
                                Console.WriteLine(oUser.Name +":"+ view.Title);
                            }
                        }
                        oElevWeb.Dispose();
                        oElevSite.Dispose();
                    }
                    catch
                    {

                    }
                });
            }
        }
3
  • I'm running this through powershell using several accounts. My administrator account, farm account, none work. These accounts have full control on the site. – ferr Jun 19 '14 at 17:24
  • your code performs the brute method i'm trying to avoid of iterating through each user. – ferr Jun 19 '14 at 17:30
  • there is no other option. – Aanchal Jun 19 '14 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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