Solved

Accessing Personal View in Sharepoint List

Posted on 2011-02-15
5
2,748 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now