The following code snippet can be used to modify list view web part.
private static void Main(string[] args)
{
var site = new SPSite("http://Servername/sites/cbteamsite");
SPWeb web = site.OpenWeb();
SPFile file = web.GetFile(pageUrl);
SPLimitedWebPartManager mgr =
file.GetLimitedWebPartManager(
(PersonalizationScope)Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
SPList list = web.Lists["Sales Announcements"];
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (wp.Title == "Sales Announcements")
{
var listWp = (ListViewWebPart)wp;
var viewId = new Guid(listWp.ViewGuid);
SPView view = list.Views[viewId];
view.ViewFields.Delete("Value");
view.ViewFields.Delete("Report_x0020_Path");
//hide check box
view.ViewFields.View.TabularView = false;
view.Update();
}
}
private static void Main(string[] args)
{
var site = new SPSite("http://Servername/sites/cbteamsite");
SPWeb web = site.OpenWeb();
SPFile file = web.GetFile(pageUrl);
SPLimitedWebPartManager mgr =
file.GetLimitedWebPartManager(
(PersonalizationScope)Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
SPList list = web.Lists["Sales Announcements"];
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (wp.Title == "Sales Announcements")
{
var listWp = (ListViewWebPart)wp;
var viewId = new Guid(listWp.ViewGuid);
SPView view = list.Views[viewId];
view.ViewFields.Delete("Value");
view.ViewFields.Delete("Report_x0020_Path");
//hide check box
view.ViewFields.View.TabularView = false;
view.Update();
}
}
Suresh I can't find ListViewWebPart in the new Sharepoint PnP Core Online CSOM Libraries. Any ideas how to accomplish the change view in web parts now?
ReplyDelete