SharePoint allows users to add views of lists and libraries on the any page within your site.
When added, users can toggle various properties of the view just as it was a web part. You can change the appearance settings, the layout etc.
If I was to provision this view pragmatically using a page schema, I wouldn’t have been even able to access half of those properties. For example, when you add a Document Library view to the page using schema XML, the markup looks like this:
<View List="MyDocumentLibrary" BaseViewID="0" WebPartZoneID="Zone1" />
There are only a few properties available when declaring a view but you can’t change the chrome type, for example. With the chrome type visible, users will be able to see some elements of the view I may want to hide.
Let’s take a look at how you can access those properties with a feature receiver once the view is provisioned to the page.
I assume you’re provisioning a new page using a SharePoint feature, which means you can reuse the same feature and add a feature receiver to it with the logic which will handle modifying the properties.
If you have an existing page and not using a receiver, you can run a code below (with few small mods) in a console application to get the same result.
If you’re interested how to do the same using PowerShell, you got to check out my new PowerShell book
// I assume you get the web either from context or site
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
foreach (SPListItem pageListItem in publishingWeb.PagesList.Items)
{
PublishingPage page = PublishingPage.GetPublishingPage(pageListItem);
if (page.Title.Equals("Page Title Im interested in",
StringComparison.InvariantCultureIgnoreCase))
{
page.CheckOut();
SPLimitedWebPartManager webPartManager =
web.GetLimitedWebPartManager(page.Url,
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
if (webPartManager.WebParts.Count > 0)
{
// I assume your page has the view only and not other webparts
XsltListViewWebPart webpart =
webPartManager.WebParts[0] as XsltListViewWebPart;
webpart.ChromeType =
System.Web.UI.WebControls.WebParts.PartChromeType.None;
webPartManager.SaveChanges(webpart);
}
page.Update();
page.CheckIn("Updated by the system);
}
}
Basically, we get a hold of the page and access it’s web part manager object, which contains all the web parts for the page. Then, we get a hold of the web part with an index 0; in your case, if you have a page with several web parts, you’d want to select the web part by its title or type.
Once you’ve got the right web part, we set it’s properties as required; in my case we’re turning off the chrome for the web part.
That’s it, the page is then checked in …
Enjoy!

