Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint Site Columns

$
0
0

Hi,

I have created four site column to a site collection and added those columns to a content type programatically. That content type is associated to a page.But when I edit the page only one site column is coming. I have written following code to create site column and add that site column to a content type which base type a Page

 if (!web.Fields.ContainsField("Field1"))
{
string Field1 = web.Fields.Add("Field1", SPFieldType.Text, false);
                            //Set the Field Properties 
                            SPFieldText x = (SPFieldText)web.Fields.GetField("Field1");
                            //Set the group for the Site column 
                            x .Group = "y";
                            x.Update();
                            web.Update();
}
if (!web.Fields.ContainsField("Field2"))
{
string Field2 = web.Fields.Add("Field2", SPFieldType.Text, false);
                            //Set the Field Properties 
                            SPFieldText z = (SPFieldText)web.Fields.GetField("Field2");
                            //Set the group for the Site column 
                            z .Group = "y";
                            z.Update();
                            web.Update();
}
if (contentType.Fields.ContainsField("Field1"))
                        {
                            SPField fieldx = web.Fields["Field1"];
                            SPFieldLink fieldLink = new SPFieldLink(fieldx);
                            contentType.FieldLinks.Add(fieldLink.Id);
                            contentType.Update(true);
                            web.Update();
                        }
if (contentType.Fields.ContainsField("Field2"))
                        {
                            SPField fieldz = web.Fields["Field2"];
                            SPFieldLink fieldLink = new SPFieldLink(fieldx);
                            contentType.FieldLinks.Add(fieldLink.Id);
                            contentType.Update(true);
                            web.Update();
                        }
Can you please tell me where I am wrong

Shubho



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>