First Post!
This Post will be showing you how you can reorder the order in which your Fields in the Content Type are displayed . This will effect the order in which they appear in the New, Edit and Display forms when the Content Type is applied to the List as well as in the Content Type Settings page:
Personally I used the following code in a Feature Event Receiver because my Content Types were declaritively created in XML/CAML, but this code can also be used if and when the Content Types are created in code.
First of all we use a string array to specify the Field order that we want to achieve using the fields static names:
1 2 3 4 5 6 7 8 9 10 11 12 13 | string[] fieldOrder = { "Title", "EventType", "TimeZone", "StartDate", "EndDate", "Location", "fAllDayEvent", "fRecurrence", "Duration", "EventCanceled", "Comments", "Category", "WorkspaceLink", "UID", "RecurrenceID", "Workspace", "RecurrenceData", "XMLTZone", "MasterSeriesItemID" }; |
Then we get an instance of the Content Type from the SPWeb object of the site we want to apply the change to:
1 | SPContentType eventContentType = (((Your SPWeb Object))).ContentTypes["Event"]; |
Using the Reorder method of FieldLinks, we can pass in the string array we declared earlier:
1 | eventContentType.FieldLinks.Reorder(fieldOrder); |
Then we use the Update method of the Content Type object, also passing in true which updates the inheriting Content Types as well (Not really required):
1 | eventContentType.Update(true); |
And voilĂ ! It’s Complete.
Complete Code Example:
Note: In the below example complete code it creates new SPSite and SPWeb objects but keep in my mind the way that you create/retrieve these objects will differ depending on where you are using the code and what is considered best practice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | string[] fieldOrder = { "Title", "EventType", "TimeZone", "StartDate", "EndDate", "Location", "fAllDayEvent", "fRecurrence", "Duration", "EventCanceled", "Comments", "Category", "WorkspaceLink", "UID", "RecurrenceID", "Workspace", "RecurrenceData", "XMLTZone", "MasterSeriesItemID" }; using (SPSite oSPSite = new SPSite("http://examplesharepointsite.com")) { using (SPWeb oSPWeb = oSPSite.OpenWeb()) { SPContentType eventContentType = oSPWeb.ContentTypes["Event"]; eventContentType.FieldLinks.Reorder(fieldOrder); eventContentType.Update(true); } } |
If you have any suggestions or notice anything that could be done better please tell me, as I am a junior SharePoint developer and infant blogger
Cheers,
Luke
I love sharepoint, however I am not very good. I read article but not fully understand. What is a content type?
Hi Jason,
Thanks for the reply. A content type is a reusable collection of metadata (columns), workflow, behavior, and other settings for a category of items or documents in a Microsoft SharePoint Foundation 2010 list or document library. Content types enable you to manage the settings for a category of information in a centralized, reusable way.
You can read more here
Thanks,
Luke
UK Segboards offering cheap UK Hoverboard for sale in all areas of UK. Our guaranteed for best price quality products of UK hoverboard for sale.
Good, clear post. Thanks Luke.
I see you share interesting stuff here, you can earn some
additional money, your website has huge potential, for the monetizing method, just
search in google – K2 advices how to monetize a website
I read a lot of interesting posts here. Probably you spend a lot of
time writing, i know how to save you a lot of work, there is an online tool that creates unique,
google friendly posts in seconds, just type in google – laranitas free content source
What’s Going down i am new to this, I stumbled upon this I have
found It absolutely helpful and it has aided me out loads.
I am hoping to contribute & aid other users
like its aided me. Good job.
UK Segboards offering cheap UK Hoverboard for sale in all areas of UK. Our guaranteed for best price quality products of UK hoverboard for sale.
Youu ought to take part in a contest for one of the greatest websites on the web.
I am going to recommend this web site!
With any luck , you a few kind of website or blog a person mmay send people who register.
Whatever endeavors that all of us ourselves into,always put the
above traits into account.
Hi admin, i must say you have hi quality articles here.
Your page should go viral. You need initial traffic boost only.
How to get it? Search for: Mertiso’s tips go viral