Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to set the url title of a list view programmatically (preferrably CSOM/JSOM) so we could for example create a view whose View Name is "My View" and its web address ends with "/MyView.aspx"

enter image description here

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Following code sample should help:

SP.ViewCreationInformation viewCreationInformation = new SP.ViewCreationInformation();
viewCreationInformation.Title = "My View";
viewCreationInformation.ViewTypeKind = SP.ViewType.None;
viewCreationInformation.RowLimit = 30;

//Make sure that the name of the fields should be equal to 1 any of the associated SiteColumns Internal Name. The Fields in the view will appear in the same order as declared here.
viewCreationInformation.ViewFields = new string[]{"Title","Created","Modified"};
viewCreationInformation.SetAsDefaultView = true;

oList.Views.Add(viewCreationInformation);

ctx.Load(oList.Views);
ctx.ExecuteQuery();

If you want the URL and Title to be different, you might need to play a trick with SharePoint..

That is first create the view with title "MyView" and then get the view again and update the Title value to "My View"..

share|improve this answer
    
Can we change the url of an existing view? –  thomius Apr 21 at 11:53
    
I don't think that is possible.. SharePoint stores the URL and even if you update the Title, it won't change the URL.. –  Arsalan Adam Khatri Apr 21 at 11:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.