Link to home
Start Free TrialLog in
Avatar of NZWizard
NZWizard

asked on

Accessing Personal View in Sharepoint List

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

Avatar of raybies
raybies
Flag of Australia image

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

Avatar of NZWizard
NZWizard

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of raybies
raybies
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
HI raybies
You are a savier ,

Thank  you very very much it worked perpect..
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