SharePoint对象模型设置字段是否在新建编辑显示页面中显示
SharePoint对象模型设置字段是否在新建编辑显示页面中显示<div class="postbody"><div id="cnblogs_post_body">在SharePoint中如果使用页面方式不管是新建的字段还是编辑老字段,其都不能设置字段是否在新建NewForm.aspx、显示DispForm.aspx、编辑EditForm.aspx页面中显示。而通过SharePoint对象模型就可以轻松实现此功能。每个字段的定义中都包括:ShowInDisplayForm、ShowInEditForm、ShowInNewForm属性,使用Ture和False来设置是否显示,其中还有一个ShowInListSettings属性用来设置字段是否在&ldquo;列表设置&rdquo;页面中显示。
现在我们将通知列表中指定某个字段在新建NewForm.aspx、显示DispForm.aspx、编辑EditForm.aspx和&ldquo;列表设置&rdquo;页面的显示情况,C#代码如下:
<div class="cnblogs_code">/// <summary>/// 设置字段是否显示在相应的页面中/// </summary>/// <param name="web"></param>/// <param name="listName"></param>protected void SetFieldShowPage(SPWeb web, string listName){ SPList list = web.Lists; Microsoft.SharePoint.SPField field = list.Fields.GetField("txtField"); //字段不在DispForm.aspx页面中显示 field.ShowInDisplayForm = false; //字段在EditForm.aspx页面中显示 field.ShowInEditForm = true; //字段不在NewForm.aspx页面中显示 field.ShowInNewForm = false; //字段在列表设置页面中显示 field.ShowInListSettings = true; //字段在视图中显示 field.ShowInViewForms = true; field.Update();}
页:
[1]