Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accessing Personal View in Sharepoint List

Posted on 2011-02-15
5
Medium Priority
?
3,103 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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