TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
CSOM: Create Duplicate View in SharePoint List
Shantha Kumar T
May 08
2016
Code
2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
//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();
}
Duplicate View
CSOM
saveAsNewView