Hi,
We all know that re ordering of fields from SharePoint UI is pretty easy. Yes it is. But in this post, we are going to see how we can do the same with the help of code.
It is very simple. Just write down following code and you should be good to go. Before that just have a look at the following list that I have created just to show you the original order of the fields.
Now write down the following code and that will change the order in which we have specified in the array. Do remember that in case the field name has space in between, then you must give _x0020_ as replacement of the space. If you do not give _x0020_ then also it will work without any problem and you will not be able to see these re ordering of fields on the form and then you might wonder why it is not changing? So take care of that.
I've also shown how to make field required.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (SPSite site = new SPSite("{site_url}"))
{
using (SPWeb web = site.OpenWeb())
{
SPContentType contentType = web.Lists["Reorder Fields Test List"].ContentTypes["Item"];
SPFieldLinkCollection fields = contentType.FieldLinks;
web.AllowUnsafeUpdates = true;
fields.Reorder(new[] { "First_x0020_Name", "Last_x0020_Name", "Blood_x0020_Group", "Title", "Birth_x0020_Date" });
fields["Birth_x0020_Date"].Required = true;
contentType.Update();
web.AllowUnsafeUpdates = false;
}
}
}
}
And see the output.
Well one important thing to note here is that this will change the order of fields in the New and Edit form. but it won't change for display form. for that you need to change the view.
SharePoint Kings,Technosavvy guys hunting SharePoint Challenges... SharePoint 2013, SharePoint 2010, MOSS 2007, Windows Workflow Foundation, Project Server and Other Related Technologies.
Tuesday, March 29, 2011
Wednesday, March 16, 2011
Wednesday, March 2, 2011
Remove table of content maximum limit
We know how table of content web part can help us providing a way to show up all links of libraries and lists on one single page for ease of access.
However when it comes to a size limit, it can show up to 50 links at a time. It does not show if you have more than 50 items.
So, how to remove this limitation? Follow the steps below. Make sure that you take a backup of web.config file of the port number of web server. (Do the same for each server if you have farm environment)
1) Open web.config for specific port for web application.
(C:\inetpub\wwwroot\wss\virtualdirectories\port)
2) Find below entries
<add name="GlobalNavSiteMapProvider" description="CMS provider for Global navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Global" EncodeOutput="true" />
<add name="CombinedNavSiteMapProvider" description="CMS provider for Combined navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Combined" EncodeOutput="true" />
<add name="CurrentNavSiteMapProvider" description="CMS provider for Current navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="true" />
<add name="CurrentNavSiteMapProviderNoEncode" description="CMS provider for Current navigation, no encoding of output" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="false" />
We need to add DynamicChildLimit="0" before the end tag "/>" on each line to disable the default 50 elements limit.
0 means no limit, If you want to limit it to specific number, specify that number there.
Example
<add name="GlobalNavSiteMapProvider" description="CMS provider for Global navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Global" EncodeOutput="true" DynamicChildLimit="0" />
Remember, you have to add this attribute in all four tags.
However when it comes to a size limit, it can show up to 50 links at a time. It does not show if you have more than 50 items.
So, how to remove this limitation? Follow the steps below. Make sure that you take a backup of web.config file of the port number of web server. (Do the same for each server if you have farm environment)
1) Open web.config for specific port for web application.
(C:\inetpub\wwwroot\wss\virtualdirectories\port)
2) Find below entries
<add name="GlobalNavSiteMapProvider" description="CMS provider for Global navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Global" EncodeOutput="true" />
<add name="CombinedNavSiteMapProvider" description="CMS provider for Combined navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Combined" EncodeOutput="true" />
<add name="CurrentNavSiteMapProvider" description="CMS provider for Current navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="true" />
<add name="CurrentNavSiteMapProviderNoEncode" description="CMS provider for Current navigation, no encoding of output" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="false" />
We need to add DynamicChildLimit="0" before the end tag "/>" on each line to disable the default 50 elements limit.
0 means no limit, If you want to limit it to specific number, specify that number there.
Example
<add name="GlobalNavSiteMapProvider" description="CMS provider for Global navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Global" EncodeOutput="true" DynamicChildLimit="0" />
Remember, you have to add this attribute in all four tags.
Tuesday, March 1, 2011
Column ordering link does not appear
I was working on one list for some stiff and suddenly I found that I was not able to locate column ordering in list settings page. Well, where did it go? Because I saw it earlier and suddenly it is not there now.
Well, the only change that happened was I enabled the management of content types and hence it went inside the content type.
So if you do not see column ordering and enabled the content types, it will be in content type settings, not in the list settings page.
Well, the only change that happened was I enabled the management of content types and hence it went inside the content type.
So if you do not see column ordering and enabled the content types, it will be in content type settings, not in the list settings page.
Subscribe to:
Posts (Atom)
Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!
If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com