将克隆的 SPView 添加到列表

发布于 2024-08-14 03:47:01 字数 558 浏览 1 评论 0原文

好的,有谁知道如何/是否可以克隆 SharePoint 视图,然后将其添加到列表中。 SPViewCollection.Add 重载不会采用 SPView 的实例,我找不到任何指示如何执行此操作的文档。

例如,我基本上想这样做:

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!

最终结果是我希望新视图复制原始视图的行为,但更改的查询除外。我愿意走另一条路,但我不确定那是什么。 (我注意到 BaseViewID 属性可能有帮助,但它是只读的)。

任何建议或提示将不胜感激。

Ok, does anyone know how/if you can clone a SharePoint view and then add it to a list. The SPViewCollection.Add overloads will not take an instance of SPView and I couldn't find any documentation that indicated how to do so.

For example I would like to 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!

The end result is I want the new View to copy the behavior of the original view with the exception of an altered query. I'm willing to go a different route, but I'm not sure what that is. (I noticed the BaseViewID property that may help, but it's read-only).

Any suggestion or hints would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨轻弹 2024-08-21 03:47:01

如果使用 SPView.Clone(title, rowlimit, paged, default) 克隆 SPView,则它会作为新视图自动添加到该列表中。或者,至少是当您调用 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 的任何内容。
自从你发布这篇文章以来已经有几个月了,但我想我会把这篇文章留给其他在搜索这些东西时遇到这个问题的人。

If you clone an SPView using SPView.Clone(title, rowlimit, paged, default), then it is automatically added to that list as a new view. Or, at least, it is when you call Update() (much like SPList.Items.Add()). I do the following, for example, to create a cloned view that differs only in the query:

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();

And now my list (thisList, as it were) has a new view that has all the same properties as the default view except now it groups by a column "dlCategory" and filters out anything whose "dlPriority" is not 2.
It's been months since you posted this but I figured I'd leave this out for anyone else who runs across this while doing a search for this stuff.

尴尬癌患者 2024-08-21 03:47:01

我知道这并不完全是您所希望的,但是 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);

您将获得一个具有新名称和完全相同内容的新视图。

I know this is not exactly what you hoped for, but SPFiles are buggy with views for a binary copy, so try just passing the same values on the overload:

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);

You get a new view with a new name and the exact same content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文