//Author: Shantha Kumar T
//Method used: SP.List.saveAsNewView(string oldViewGuid, string newName, boolean privateView, string uri)
//Paramteres:
////oldViewGuid: Guid of the view in string format
////newName: Name for the new view
////privateView: Boolean value to set private view or public view
////uri: url for new view
//Supports: SharePoint 2013 + and SharePoint Online
string weburl = "https://sharepointsite";
string listTitle="Test List";
Guid guidOldView = new Guid("59A88256-510F-4C66-836E-E91C6D30A73A");
string newViewName = "Duplicate View";
string newViewUrl = "duplicateview.aspx";
CreateDuplicateView(credentials, weburl, listTitle, guidOldView, newViewName, newViewUrl);
private static void CreateDuplicateView(ICredentials credentials, string weburl, string listTitle, Guid guidOldView, string newViewName, string newViewUrl)
{
using (ClientContext ctx = new ClientContext(weburl))
{
ctx.Credentials = credentials;
Web oweb = ctx.Web;
ListCollection lists = oweb.Lists;
List targetList = lists.GetByTitle(listTitle);
ClientResult<string> res = targetList.SaveAsNewView(guidOldView.ToString(), newViewName, false, newViewUrl);
ctx.ExecuteQuery();
Console.WriteLine("View Successfully created in url: "+ res.Value);
}
Console.WriteLine("Press any key to exit...");
Console.Read();
}This code snippet used to create a duplicate view based on another view in SharePoint List using CSOM.
