Solved

Accessing Personal View in Sharepoint List

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

20 Experts available now in Live!

Get 1:1 Help Now