Adding a cloned SPView to the list

Ok, does anyone know how / if you can clone a SharePoint view and then add it to the list. Overloads of SPViewCollection.Add will not have an instance of SPView, and I could not find any documentation that would indicate how to do this.

For example, I would essentially do this:

var myList = SPContext.Current.Web.List;//or something similar
var baseView = myList.DefaultView;
var myNewView = baseView.Clone("my view", base.RowLimit, base.Paged, false);
myNewView.Query = "<Where>......</Where>";
myList.Views.Add(myNewView);//this overload doesn't exist!

As a result, I want the new View to copy the behavior of the original view, except for the modified request. I am ready to go the other way, but I'm not sure what it is. (I noticed the BaseViewID property, which may help, but it is read-only).

Any suggestion or hints would be appreciated.

+3
source share
2 answers

SPView SPView.Clone(, rowlimit, paged, default), . , , Update() ( SPList.Items.Add()). , , , :

SPView thisView = thisList.DefaultView;
thisView = thisView.Clone("High Priority", 100, true, false);
thisView.Query = "<GroupBy Collapse=\"TRUE\" GroupLimit=\"100\"><FieldRef Name=\"dlCategory\" /></GroupBy><Where><Eq><FieldRef Name=\"dlPriority\"></FieldRef><Value Type=\"Number\">2</Value></Eq></Where>";
thisView.Update();

(thisList ) , , , "dlCategory" , "dlPriority" - 2. , , , , , .

+10

, , , SPFiles , :

SPList list = SPContext.Current.Web.Lists["Test"];
SPViewview = list.Views["All Items"];
list.Views.Add(view.Title + "_NEW", view.ViewFields.ToStringCollection(), 
               view.Query, view.RowLimit, view.Paged, view.DefaultView);

.

+4

Source: https://habr.com/ru/post/1724747/


All Articles