gpt4 book ai didi

visual-studio-2010 - 共享点 2010 : edit a view programmatically

转载 作者:行者123 更新时间:2023-12-02 00:37:43 24 4
gpt4 key购买 nike

正如标题所说,我需要一种方法来以编程方式编辑 Sharepoint 2010 中列表的现有 View 。我发现了很多关于创建新 View 的示例:

SPList documents = web.Lists["Documents"];
StringCollection fields = new StringCollection();
fields.Add("Type");
fields.Add("Name");
fields.Add("File Size");
fields.Add("Modified");
fields.Add("Modified By");
fields.Add("Version");
var query = new XElement("Where",
new XElement("Eq",
new XElement("FieldRef", new XAttribute("Name", "Project")),
new XElement("Value", new XAttribute("Type", "Lookup"), "alpha")
)
).ToString(SaveOptions.DisableFormatting);

SPView view = documents.Views.Add(
"ProjectFilter",
fields,
query,
100,
false,
false,
Microsoft.SharePoint.SPViewCollection.SPViewType.Html,
false);

我还找到了一些关于根据显示字段编辑现有列表的示例:

SPList documents = web.Lists["Documents"];
SPview view = documents.Views["All Documents"];
view.ViewFields.Add("Price");
view.Update();

我唯一没有找到的方法是修改现有 View 并使用 CAML 查询对其进行过滤,就像我创建它时上面的示例一样

有办法吗?

最佳答案

好的,这是解决方案!

SPList documents = web.Lists["Documents"];
SPView docview = documents.Views["Project Filtered"];

var docquery = new XElement("Where",
new XElement("Eq",
new XElement("FieldRef", new XAttribute("Name", "Project")),
new XElement("Value", new XAttribute("Type", "Lookup"), "alpha")
)
).ToString(SaveOptions.DisableFormatting);

docview.Query = docquery;
docview.Update();

关于visual-studio-2010 - 共享点 2010 : edit a view programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3942225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com