Sharepoint UpdateList Method : Newly created Columns are not visible

两盒软妹~` 提交于 2019-12-10 17:22:41

问题


I worked on code .It is working successfully. But Problem i am facing is:

New Columns are not visible in List ( I tried with With Setting Required = "TRUE" ).

I tried with compairing Field Value of Both Visible and No-Visible Columns. Difference i found is : Visible Columns (Created Manually) doesn't contain Version value. wereas columns i am creating have it.

So i tried with passing null value to "ndVersion.Value".

But it is still not working and automaticaly putting some value to version.

Can you help me out in this?

I tried Solution given Here .

But it din't Worked again. :(


回答1:


There are actually several things that happen when you add a column to a list in the browser:

  • Field is added to the list
  • Field is added to list content types
  • Field is added to the default view

When you add a column using code, you may only be modifying the list, but not the content type (which defines new/edit forms) or the view (which defines list views)

                var field = list.Fields[fieldName];

                var ctype = list.ContentTypes[contentTypeId];
                var fieldref = new SPFieldLink(field);
                ctype.FieldLinks.Add(fieldref);
                ctype.Update();

                var view = list.Views[viewName];
                view.ViewFields.Add(field);
                view.Update();



回答2:


Try with setting ReadOnly property to "FALSE"




回答3:


There's a good amount of useful information on this on MSDN.

Adding Columns to Content Types

HowTo: Add a column to a list (Code Links)




回答4:


I would use the object model provided using Microsoft.Sharepoint.dll instead of using the web services.

There is problems in Sharepoint when you are adding new columns to the content type that changes are not always pushed down to the lists. I think the Sharepoint UI does this for you when you edit a content type, but when you do it yourself in code then you have to make sure that your changes are pushed down to the lists.

There are 2 ways to add content type data to a list programmatically

  • via schema.xml -> Then you have to let the list inherit from your content type, but you still have list up all the fields that you want to use from your content type.
  • via code -> Add your field to the content type, but then you have to add the content type to the list again to make sure that all fields are populated in the list


来源:https://stackoverflow.com/questions/2208113/sharepoint-updatelist-method-newly-created-columns-are-not-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!