Skip to main content

Creating SharePoint 2010 Calculated Field from code in sites with different regional settings

Say you need to create the following calculated column in different sites that have different regional settings: English, French, etc. to format the DateTime [Start Time] filed to "dd-mm-yyyy".

The following formula would look list this in English - with a comma separator:
=TEXT([Start Time],"dd-mm-yyyy")
Like this in french - with a semicolon separator:
=TEXT([Start Time];"dd-mm-yyyy")
When creating the column from from code  behind to treat this  the SPWeb.Locale.TextInfo.ListSeparator property must be used to get the correct list separator:
SPList spList = SPContext.Current.Web.Lists["List Title"];
string newFieldName = spList.Add("CalculatedField", SPFieldType.Calculated, false);
SPFieldCalculated newField = (SPFieldCalculated)spList.GetField(newFieldName);
newField.Formula = String.Format(@"=TEXT([Start Time]{0} ""dd-mm-yyyy"")", SPContext.Current.Web.Locale.TextInfo.ListSeparator);
newField.Update();

Comments

Popular posts from this blog

Oversized buttons in IE

Yeah ... just another problem with IE. Lucky for all of us there are some people that can hack their way through the IE bugs. Here is a fix for this problem: input.button {   padding: 0.25em;   width: 0;   overflow:visible; } input.button[class] { /*ie ignores [class]*/   width: auto; }

Emmet in Visual Studio Code | cheat sheet link

Support for   Emmet   snippets and expansion is built right into Visual Studio Code,   no extension required .   Emmet 2.0   has support for the majority of the   Emmet Actions   including expanding   Emmet abbreviations and snippets .   Emmet is a web-developer’s toolkit that can greatly improve your HTML & CSS workflow   Links: Emmet in Visual Studio Code   Cheat Sheet (emmet.io)  

SharePoint 2010 State Machine Workflow error: "Failed to Start Workflow"

I've been working on a custom state machine workflow for a specific content type. I've associated the workflow to the content type like this: < AssociationCategories > ContentType ; 0x01........ </ AssociationCategories > This workflow has a custom initiation form, in which I'm passing some options to the workflow. After doing the association to the content type I started getting the following error: "Failed to Start Workflow" After doing a bit of debugging and head scratching I found that in the  StartListWorkflow () method inside the initiation page in which the workflow association is retrieved from the workflowList.WorkflowAssociations list and it does not take into consideration the ContentType workflow associations. private void StartListWorkflow () { SPWorkflowAssociation association = this . workflowList . WorkflowAssociations [ new Guid ( this . associationGuid )]; this . Web . Site . WorkflowManager . StartWork...