无法在我的ItemUpdated事件接收器内的列表内容类型中隐藏字段 [英] Unable to hide a field inside a list content type inside my ItemUpdated event receiver

查看:69
本文介绍了无法在我的ItemUpdated事件接收器内的列表内容类型中隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的SharePoint服务器场2013中处理ItemUpdated()事件接收器.现在在事件接收器中,我正在创建一个新的子站点,然后我要访问一个名为"Risk&问题".然后在列表中,我要访问列表 内容类型,并将标题"字段设置为隐藏.我要在ER中实现的目标可以使用UI进行,如下所示:-

I am working on an ItemUpdated() event receiver inside my sharepoint farm 2013. now inside the event receiver i am a creating a new sub site, then i want to access a list named "Risk & Issue". then inside the list , i want to access the list content type and set the Title field as hidden. what i am trying to achieve inside my ER, can be done using the UI, as follow:-

1.转到子站点.

2.点击风险&发行"列表设置.

2. click on the "Risk & Issue" list settings.

3.点击其内容类型.

3. click on its content type.

4.点击标题列表"字段.

4. click on the Title list field.

5.将其设置为隐藏.

5. set it as hidden.

现在这是我的ER中的相关代码:-

Now here is the related code inside my ER:-

public override void ItemUpdated(SPItemEventProperties properties)
        {

            base.ItemUpdated(properties);
            //create the subsite
            SPWeb newSite = spCurrentSite.Webs.Add(curItemID, curItemSiteName, "created automatically after adding a new project item", Convert.ToUInt16(1033), webTemplate, false, false);
            //code goes here
            newSite.Update();
            // loop through the new site lists
            for (int i = 0; i < newSite.Lists.Count; i++)
            {
            if (newSite.Lists[i].Title.ToLower() == "risk & issue")
                {

                    SPContentType riskCT =  newSite.Lists[i].ContentTypes[0];
                    if (riskCT.Fields.ContainsFieldWithStaticName("Title") == true)
                    {
                    SPField titlefield=   riskCT.Fields.GetFieldByInternalName("Title");
                    titlefield.Hidden = true; 
                    riskCT.Update();

                    }
                }
            }
            newSite.Dispose();
        }

现在代码可以正常工作而不会引发任何异常,但是新站点内的title字段仍将根据需要设置,而不是被隐藏.所以在我上面的代码中似乎这句话:-

now the code will work without raising any exception, but the title field inside the new site will still be set as required, and not as hidden . so seems this sentence inside my above code:-

titlefield.Hidden = true; 

没有任何作用,或者至少没有将列表标题类型内的标题"列表列隐藏..so,有人可以将我从ItemUpdated ER内的列表内容类型中隐藏列表列吗?

is not having any effect, or atleast is not hiding the Title list column inside the list conent type ..so can anyone adivce how i can hide a list column from a list content type inside an ItemUpdated ER ??

推荐答案

尝试使用以下代码:

 riskCT.FieldLinks["Title"].Hidden = true;
                        //titlefield.Hidden = true;
                        riskCT.Update();


这篇关于无法在我的ItemUpdated事件接收器内的列表内容类型中隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆