views:

442

answers:

4

Hi,

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. :(

A: 

Try with setting ReadOnly property to "FALSE"

Jene
i tried it also.but still it's not working.
Preeti Singh
+1  A: 

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();
Tom Clarkson
Thanx Tom,But i don't know how to Modify "content type and view" of list ?Can provice me sample code links?
Preeti Singh
I added some code - you'll need to expand on it depending on your requirements of course, but those collections/objects should give you a good starting point.
Tom Clarkson
A: 

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)

Nick Haslam
A: 

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
armannvg