Calculated field

If you are defining a SharePoint list using declarative definitions in Visual Studio, you won’t find calculated field in the field types. I am using two examples, the first one is with date and the other one is with integer.

Date data type:

The solution will be create your field with any data type and go to the schema file and manually do the following changes:

  <Field Type="Calculated" DisplayName="ValidationDays" EnforceUniqueValues="FALSE" Indexed="FALSE" 
             Format="DateOnly" LCID="1033" ResultType="Text" ReadOnly="TRUE"
             StaticName="ValidationDays" Name="ValidationDays">
          <FieldRef Name="StopDate" />
          <FieldRef Name="StartDate" />
  • Type –> Calculated
  • ReadOnly –> True
  • Add the formula <Formula>=StartDate-StopDate</Formula>
  • Add the field ref


<FieldRef Name=”StopDate” />

<FieldRef Name=”StartDate” />


Deploy the feature to the SharePoint server and activate the feature.

Test the list.

Integer data type:

Repeat the same steps and the field definition in the schema field will be:

<Field Name="FreeTickets" ID="{90dfb1f0-257e-4530-b885-84842594323e}" Type="Calculated" >
				<Formula>= Tickets - SoldTickets</Formula>
          <FieldRef Name="Tickets" />
          <FieldRef Name="SoldTickets" />

Deploy the feature to the SharePoint server and activate the feature.

Test the list.

Error Occurred In Deployment Step ‘Recycle IIS Application Pool’ – Invalid Namespace SharePoint

One of the common deployment errors is Error Occurred In Deployment Step ‘Recycle IIS Application Pool’ – Invalid Namespace SharePoint. It occurs if the developers are trying to deploy SharePoint solution to SharePoint 2019 on premises.

The solution: you need to install IIS 6 management backward compatibility.

The steps (windows server):

  1. serer manager
  2. Click on “Add Roles and Feature”
  3. Click next in the appeared dialog until you reach “Server Roles”.
  4. expand “Web Server (IIS)” and then expand “Management Tools”
  5. from  “IIS 6 Management Compatibility” select “IIS 6 WMI Compatibility”, “IIS 6 Metabase Compatibility” & “IIS 6 Management Console” and click Next.
  6. Click install

Prevent Special Characters in Single line text field

One of the data validation challenges is prevent the users from entering special characters in text field (Single line of text) . In this validation formula, nested if & isError will be used as in the following formula

=AND(IF(ISERROR(FIND(“,”,[ColumnName])),TRUE), IF(ISERROR(FIND(“&”,[ColumnName])),TRUE), IF(ISERROR(FIND(“;”,[ColumnName])),TRUE), IF(ISERROR(FIND(“[“,[ColumnName])),TRUE), IF(ISERROR(FIND(“+”,[ColumnName])),TRUE), IF(ISERROR(FIND(“:”,[ColumnName])),TRUE), IF(ISERROR(FIND(“)”,[ColumnName])),TRUE), IF(ISERROR(FIND(“-“,[ColumnName])),TRUE), IF(ISERROR(FIND(“*”,[ColumnName])),TRUE), IF(ISERROR(FIND(“(“,[ColumnName])),TRUE), IF(ISERROR(FIND(“$”,[ColumnName])),TRUE), IF(ISERROR(FIND(“%”,[ColumnName])),TRUE), IF(ISERROR(FIND(“~”,[ColumnName])),TRUE), IF(ISERROR(FIND(“#”,[ColumnName])),TRUE), IF(ISERROR(FIND(“]”,[ColumnName])),TRUE), IF(ISERROR(FIND(“.”,[ColumnName])),TRUE), IF(ISERROR(FIND(“!”,[ColumnName])),TRUE), IF(ISERROR(FIND(“@”,[ColumnName])),TRUE), IF(ISERROR(FIND(“/”,[ColumnName])),TRUE), IF(ISERROR(FIND(“\”,[ColumnName])),TRUE))

Also, the same formula can be used to prevent numeric values to be entered in the text field and replacing the characters with the numbers.

I hope this will be helpful for the SharePoint developers.

Enjoy single line of text without special characters

How to make SharePoint Attachment required

List item attachment in many cases needs to be required and at the same time the developer doesn’t want to edit the form using SharePoint designer. The trick is pretty easy, just edit the newForm.aspx to the list in browser and add content editor. Then, copy and paste the following script.

Note: you can change the message in the alert

<script type="text/javascript" language="javascript">
function PreSaveAction() {
if (document.getElementById('idAttachmentsRow').style.display=='none' )
     alert('Attachment is Mandatory! Please attach Documents.');
     return false ;
else {  return true;  }

Enjoy the required attachment with the alert.

E-mail Validation

SharePoint developers are facing many challenges in the data validations. One of these challenges is validating the email address. Emails are stored in SharePoint column with data type single line text and this will allow the users to enter any character series with maximum number 255 which will require data validation.

  1. Validate if the e-mail column includes . & @


2. Validate if the e-mail column includes . & @ and @ comes after . at least by 2 characters


3. Validate if the e-mail column includes . & @ and @ comes after . at least by 2 characters. Also, there is at least 2 characters after @


Enjoy a valid email data entry.