Home > Blogs > Eric Shupps | The SharePoint Cowboy > Posts > Using PowerShell to Set List View Parameters in SharePoint Web Parts
 
Eric Shupps eshupps The SharePoint Cowboy is the founder and President of BinaryWave, a leading provider of operational intelligence solutions for Microsoft SharePoint. Eric Shupps eshupps The SharePoint Cowboy has worked with SharePoint Products and Technologies since 2001 as a consultant, administrator, architect, developer and trainer. he is an advisory committee member of the Dallas/Ft. Worth SharePoint Community group and participating member of user groups throughout the United Kingdom. Eric Shupps eshupps The SharePoint Cowboy has authored numerous articles on SharePoint, speaks at user group meetings and conferences around the world, and publishes a popular SharePoint blog at http://www.sharepointcowboy.com. Presentations by Eric Shupps eshupps The SharePoint Cowboy Webinar - Migrating Legacy On Premise Solutions to SharePoint Online and Windows Azure featuring Eric Shupps Who are you and what do you want - Working with OAuth in SharePoint 2013 SharePoint is Talking Are You Listening? Eric Shupps SharePoint 2013 Performance Enhancements Taking Advantage of the SharePoint 2013 REST API Eric Shupps on Improving Performance with New Features in SharePoint 2013 SharePoint 2013 New and Improved Migrating Legacy On Premise Solutions to SharePoint Online and Windows Azure Eric Shupps Presents SharePoint 2013 Real World Help Desk App End to End Windows Azure Apps for SharePoint 2013 Eric Shupps Demonstrates Customizing the Visual Studio 2010 SharePoint Deployment Process Introduction to SharePoint Development SharePoint 2010 Unit and Integration Testing with Eric Shupps Building Enterprise Records Management Solutions for SharePoint 2010 Taming Information Chaos in SharePoint 2010 SharePoint 2010 Performance and Capacity Planning Best Practices Building Dynamic Applications with the SharePoint Client Object Model Articles by Eric Shupps eshupps The SharePoint Cowboy Eric Shupps' Ten Steps to Optimize SharePoint Performance Webcasts by Eric Shupps eshupps The SharePoint Cowboy Secrets of SharePoint Part 5: Configuring Microsoft Office SharePoint Server 2007 for Optimal Performance Creating End User SharePoint Solutions for Performance and Scalability SharePoint 2010 Performance Enhancements for Administrators by Eric Shupps Microsoft SharePoint Server 2010 for the ASP.NET Developer Eric Shupps on Following Best Practices and Avoiding Common Errors with Microsoft Office SharePoint Server 2007 Development Eric Shupps - SharePoint Performance and Capacity Planning Essentials Troubleshooting Common Performance Problems in SharePoint 2010 Videos by Eric Shupps eshupps The SharePoint Cowboy Channel 9 Interview with Eric Shupps SharePoint TechTalk with Eric Shupps - Different Views on Social Computing SharePoint Post-Deployment Planning and Management with Eric Shupps SmartTrack for SharePoint Feature Overview SmartTrack for SharePoint Podcasts by Eric Shupps eshupps The SharePoint Cowboy SharePoint Pod Show - Design for Performance (Eric Shupps) SharePoint Pod Show - Test Driven Development with Andrew Woodward and Eric Shupps eshupps The SharePoint Cowboy Run As Radio - Eric Shupps Improves SharePoint Performance
SmartTrack for SharePoint Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave

 
​The SharePoint Cowboy


photo of  Eric Shupps
BinaryWave
611 S. Main St., Suite 400
Grapevine , TX , 76051 USA
Eric Shupps and Eric Alan Shupps with BinaryWave the BinaryWave Inc in BinaryWave Incorporated around SmartTrack beside SharePoint Monitoring through SharePoint alongside SharePoint Monitoring visiting @eshupps via eshupps near SharePoint performance and SharePoint management. The SharePoint cowboy eshupps BinaryWave and more on Operational Intelligence via Eric Alan Shupps SharePoint blog. SharePoint monitoring is a hot topic along with SharePoint Performance Measurement and SharePoint tips and tricks from Eric Shupps for SmartTrack. Another Eric Shupps on Technology and Eric Shupps on SharePoint with a new SharePoint Post from Eric Shupps. New BinaryWave post through BinaryWave Inc. and with another SharePoint blog we get to Eric Alan Shupps Blog about SharePoint development. That's Eric Shupps - BinaryWave or Eric Alan Shupps Fort Worth Grapevine Texas Dallas of BinaryWave talking about BinaryWave Operational Intelligence at the SharePoint Cowboy blog and on twitter as @eshupps. Of course SharePoint Administration is on topic for eshupps and another great post from Eric Shupps regarding BinaryWave SharePoint and SharePoint Maintenance.
September 12
Using PowerShell to Set List View Parameters in SharePoint Web Parts

While working on some modifications to the SharePoint 2010 blog site template I ran across an interesting problem. I was trying to duplicate the functionality of a particular web part; in this case, the Posts web part which outputs a formatted display of list items on the Category.aspx page of a blog site. The default web part was listed in the contents page (reachable using the "?contents=1" query string parameter) as a basic XsltListViewWebPart, which meant that I should be able to drop the Posts web part from Lists and Libraries in the web part gallery, set the view, and get the desired results. If only it were that simple.

No matter which view I picked, all the web part showed was a standard list view with rows and columns, not the nicely formatted view with the calendar page image, title link and summary information that I was after. Since it was a stock list view web part I knew it was using a view to fetch the data and then transforming it in XSL but there didn't seem to be any way to force it into using the correct view. Assuming that the view itself might be hidden from the drop-down selector, I turned to PowerShell to see if I could find out what was going on. I began by iterating through the web parts on the page to find the one I wanted and writing out the view ID:

$site = new-object Microsoft.SharePoint.SPSite("http://www.binarywave.com/blogs/eshupps")

$web = $site.openweb()

$webpartmanager = $web.GetLimitedWebPartManager("http://www.binarywave.com/blogs/eshupps/Lists/Categories/Category.aspx",
[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

for($i=0; $i -lt $webpartmanager.WebParts.Count; $i++) { if($webpartmanager.WebParts[$i].Title -eq "Posts")
{ write-host $webpartmanager.WebParts[$i].ViewId } }

The value I got in return was "8". Well, ok, that didn't tell me much, so I had a look at the schema.xml file for the Posts list in the Blog site template (located at \14\template\sitetemplates\blog\lists\posts\schema.xml). I found the <View> node with a BaseViewID value of "8" and compared it to another node with a BaseViewID value of "1". Aha! The "1" view refers to AllItems.aspx and contains a DisplayName property along with a URL value whereas "8", like a few others in the same schema, has no such information. Clearly, these are hidden from the View selector of the web part properties, which is why I was unable to pick the correct view in the UI. Now the only question was, could I set the view (and any other web part parameters I desired) programmatically? A few changes to the PowerShell script applied to the out-of-the-box list view web part achieved the desired result:

$site = new-object Microsoft.SharePoint.SPSite("http://www.binarywave.com/blogs/eshupps")

$web = $site.openweb()

$webpartmanager = $web.GetLimitedWebPartManager("http://www.binarywave.com/blogs/eshupps/Development/Development.aspx",
[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

for($i=0; $i -lt $webpartmanager.WebParts.Count; $i++) { if($webpartmanager.WebParts[$i].Title -eq "Posts")
{ $wp = $webpartmanager.WebParts[$i]; $wp.ViewGuid="{1E720D19-01A0-4B90-A14B-73CFC85092F8}"; $wp.ViewId=8;
$wp.ChromeType="None"; $webpartmanager.SaveChanges($wp); } }

Now the web part shows the proper view even though it's hidden from the UI. Although this particular example applies to artifacts in the Blog site template, I'm pretty sure the same mechanism is being used elsewhere, with "hidden" views specified in the list schema. In this case I used PowerShell to solve the problem but could have just as easily written a console application (or application page, for that matter) to do the same thing. Either way, if the list view you want doesn't show up in the selector, a bit of simple code similar to that shown above will fix it right up.

 

Comments

View Flags

Eric,
FYI... Here are the view flags.

None = 0L,
Html = 1,
ClientModified = 2,
TabularView = 4,
Hidden = 8,
LockWeb = 16,
ReadOnly = 32,
FailIfEmpty = 64,
FreeForm = 128,
FileDialog = 256,
FileDialogTemplates = 512,
AggregationView = 1024,
Grid = 2048,
Recursive = 4096,
RecurrenceRowset = 8192,
Contributor = 16384,
Moderator = 32768,
Threaded = 65536,
Chart = 131072,
Personal = 262144,
Calendar = 524288,
Default = 1048576,
FilesOnly = 2097152,
Ordered = 4194304,
Mobile = 8388608,
DefaultMobile = 16777216,
IncludeVersions = 33554432,
Gantt = 67108864,
IncludeRootFolder = 134217728,
DefaultViewForContentType = 268435456,
HideUnapproved = 536870912,
RequiresClientIntegration = 1073741824,
Unknown = 2147483648
 on 9/17/2012 2:45 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Comment Date *

Select a date from the calendar.
Enter the current date to prevent automated spambot comments.

Spam Prevention *


How many letters, not including spaces, does it take to spell "SharePoint Cowboy"?

Attachments

 
photo of Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave Eric Shupps
BinaryWave
611 S. Main St., Suite 400
Grapevine , TX , 76051 USA

 
 
 
Eric Shupps Eric Alan Shupps eshupps @eshupps SharePoint Cowboy BinaryWave 

Eric Shupps LinkedIn Eric Shupps Twitter Eric Shupps Facebook Eric Shupps Google+
 
 

 


 


BinaryWave Eric Shupps eshupps The SharePoint Cowboy SharePoint monitoring SharePoint monitoring tool SharePoint metrics SharePoint administratrion SharePoint monitoring best practices SharePoint management SharePoint management tool SharePoint operations SharePoint operationsmanagement SharePoint administration SharePoint administration tool SharePoint SLA SharePoint service level agreement SharePoint operational intelligence SharePoint performance SharePoint performance monitoring SharePoint analytics SharePoint real-time SharePoint intelligence SharePoint ITIL SharePoint service operations SharePoint uptime SharePoint alerts SharePoint health SharePoint tools SharePoint metrics SharePoint diagnostics SharePoint SmartTrack SmartTrack Operational Intelligence


Copyright © 2013 BinaryWave, Inc. All rights reserved.
This site is brought to you by BinaryWave in cooperation with Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy. We hope you enjoy the SharePoint-related content on topics such as performance, monitoring, administration, operations, support, business intelligence and more for SharePoint 2010, SharePoint 2013 and Office 365 created by Eric Shupps The SharePoint Cowboy. We also hope you will visit our product pages to learn more about SmartTrack, Operational Analytics for SharePoint, SharePoint monitoring, and SharePoint administration, while also discovering great offers from our partners. Please visit the blog of Eric Alan Shupps, Twitter handle @eshupps, for more information on application development, the SharePoint community, SharePoint performance, and general technology topics. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy is the founder and President of BinaryWave, a leading provider of operational support solutions for SharePoint. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy has worked with SharePoint Products and Technologies since 2001 as a consultant, administrator, architect, developer and trainer. He is an advisory committee member of the Dallas/Ft. Worth SharePoint Community group and participating member of user groups throughout the United Kingdom. Eric Shupps Eric Alan Shupps eshupps @eshupps The SharePoint Cowboy has authored numerous articles on SharePoint, speaks at user group meetings and conferences around the world, and publishes a popular SharePoint blog at http://www.binarywave.com/blogs/eshupps.