SPFieldCalculated Class
Represents a calculated field in a list.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
If you set the properties of the SPFieldCalculated class, you must call the Update method for changes to take effect in the database.
Use the Formula property to implement a formula in a calculated field. For information about the different kinds of formulas that you can use, see Calculated Field Formulas.
Note
|
|---|
|
Windows SharePoint Services 3.0 does not support inheriting from this class. |
The following example creates a calculated field in a list and adds it to a view. The calculated field displays "Yes" if the value of MyColumn2 is greater than MyColumn1.
using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Website_Name"]) { SPList oList = oWebsite.Lists["MyList"]; SPFieldCollection collFields = oList.Fields; string strNewFieldName = collFields.Add("MyNewColumn", SPFieldType.Calculated, false); SPFieldCalculated strNewField = (SPFieldCalculated)collFields[strNewFieldName]; strNewField.Formula = "=[Column1]<[Column2]"; strNewField.Update(); SPView oView = oList.Views["MyView"]; SPViewFieldCollection collViewFields = oView.ViewFields; collViewFields.Add(strNewFieldName); oView.Update(); }
Note |
|---|
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects. |
Or, sharepoint designer can be used to disable output escaping in the xslt for the field on the display.
Why make the class sealed? What if you want to make a list that composes a URL out of values in the other columns? Seems like that would be such a small change from MSFT.
- 12/21/2011
- Wow Workflow
Plese update the note to
Windows SharePoint Services 3.0 and MOSS 2010 does not support inheriting from this class.
reason:class haven't public constructor.
- 11/9/2011
- Martin Winzig
Note