将克隆的 SPView 添加到列表
好的,有谁知道如何/是否可以克隆 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用 SPView.Clone(title, rowlimit, paged, default) 克隆 SPView,则它会作为新视图自动添加到该列表中。或者,至少是当您调用 Update() 时(很像 SPList.Items.Add())。例如,我执行以下操作来创建仅在查询中不同的克隆视图:
现在我的列表(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:
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.
我知道这并不完全是您所希望的,但是 SPFiles 对于二进制副本的视图存在错误,因此尝试在重载中传递相同的值:
您将获得一个具有新名称和完全相同内容的新视图。
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:
You get a new view with a new name and the exact same content.