Solved

Accessing Personal View in Sharepoint List

Posted on 2011-02-15
5
2,830 Views
Last Modified: 2016-04-26
Hi Experts
I am farm admin in a SharePoint farm in my company . I want to know how many users having personal view in a SharePoint list? And users identity?

I want to do it programmatically. Any Idea how to achieve this?
Any help appreciated

I tried with following code but only giving me my personal view, not all personal views from all users.


string site = Convert.ToString(txtsiteUrl.Text);
            string list = Convert.ToString(txtListName.Text);


            SPSite spsite = new SPSite(site);

            SPWeb spweb = spsite.OpenWeb();

            SPList splist = spweb.Lists[list];

            SPViewCollection views = splist.Views;

            foreach (SPView view in views)
            {
                if (view.PersonalView)
                {
                    Response.Write(view.Title + "</br>");
                    Response.Write(view.Views.Count + "</br>");
                }
            }




Thanks

0
Comment
Question by:NZWizard
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:raybies
ID: 34903867
Instantiate SPSite with the system account.

SystemAccount.UserToken
SPSite spsite = new SPSite(site);
SPWeb spweb = spsite.OpenWeb();
SPSecurity.RunWithElevatedPrivileges(delegate()
{
	try
	{
		SPSite oElevSite = new SPSite(site, spweb.Site.SystemAccount.UserToken);
		SPWeb oElevWeb = oElevSite.RootWeb;		
		SPList splist = oElevWeb.Lists[list];
		SPViewCollection views = splist.Views;
		foreach (SPView view in views)
		{
			if (view.PersonalView)
			{
				Response.Write(view.Title + "</br>");
				Response.Write(view.Views.Count + "</br>");
			}
		}
		oElevWeb.Dispose();
		oElevSite.Dispose();
	}
	catch
	{
		
	}
});

Open in new window

0
 

Author Comment

by:NZWizard
ID: 34907496
Hi raybies
Thanks for your reply.I have run the code under  System Account but its not gettting access to personal view at all . Without system account I can get access to only my personal views not others .

Do you have any other ideas?

Thanks
0
 
LVL 16

Accepted Solution

by:
raybies earned 500 total points
ID: 34912155
Ok... hmm... I got, and this time I tested it ;0)
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
                    {

                    }
                });
            }
        }

Open in new window

0
 

Author Closing Comment

by:NZWizard
ID: 34912446
HI raybies
You are a savier ,

Thank  you very very much it worked perpect..
0
 

Expert Comment

by:neerajm2001
ID: 41565960
Hi Raybies/NZWizard,

It would be really very helpful if you share the powershell to delete a user's personal view for doc library, situation is like a user has exceeded number of personal views (50) and not able to access view now, getting error "The maximum number of web parts for all zones on this page has been exceeded"

Thanks in advance
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question