Hot answers tagged

20

It sounds like you've gotten two concepts slightly muddled. There are three entities that are important here: A field/column on a list (SPField and its derivatives, including SPFieldUser) A row of data (SPListItem) A data item (string, SPUser, etc. according to field type) Each row of data (List Item) has a data item for each of the fields, but fields ...


16

There are two possibilities here: 1) You need to determine if field is completely custom (added to list by a user from GUI). You can use SourceId property for this purpose. You will get Url, starting with "http://schemas.microsoft.com" for standard fields, and some random GUIDs for custom fields. Sample code: SPField field = // get your field from a list ...


12

A better way of doing this is the SPFieldLookupValue class. MSDN has a good example. In short, something like: SPListItem lookedUpItem = GetItemSomeHow(); newItem[lookupField] = new SPFieldLookupValue( lookedUpItem.ID, lookedUpItem.Title); newItem.Update();


12

John, Never tried this myself, but a comment is made http://msdn.microsoft.com/en-us/library/ms437580.aspx stating "In order to allow enter multiple values into field with Type="UserMulti" you must set attribute Mult="TRUE"."


11

FieldLinkCollection.Reorder() can reorder fields in list forms. Followings are the steps of reordering fields. Find the list Find ContentType Find FieldLinks of the ContentType Reorder columns of FieldLinks Reorder() takes an array of Internal Names of the fields. Based on the order of this array, Reorder() method reorders the fields in list forms. ...


9

Use the ID of the lookup target: using(SPSite site = new SPSite("http://test.dev.com")) using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["Suppliers"]; SPListItem item = list.AddItem(); item[SPBuiltInFieldId.Title] = "Test"; item["Product"] = 1; // Use the ID; get it from ...


8

You can add fields programmatically using list.Fields.AddFieldAsXml, providing CAML field definition with resource tokens in it. Or you can wrap SetValueForUICulture in a nice helper method, and gain a capability to use it for any SPUserResource object. We're using this approach at work, and I would not say, that it is unclear or smth like this :) It's ok, ...


7

Modified: Identifies a field that contains the last modified date and time information that is associated with the specified SharePoint Foundation object. Last_x0020_Modified: Identifies a field that contains version control information for the last modified version of the specified SharePoint Foundation list object. The ‘Modified’ column as we see in the ...


5

I've had success by not using .ID, but using InternalName with .ContainsFieldWithStaticName(). I also check Hidden and CanBeDeleted on the field as these are more system fields and not custom ones, so I'm not worried about them. Sample below SPWeb web = SPContext.Current.Web; foreach (SPList list in web.Lists) { foreach (SPListItem item in list.Items) ...


4

You can assign the SPUser object directly to the field: SPUser user = web.SiteUsers["domain\\username"]; item["MyCustomField"] = user;


4

In SharePoint 2013, client-side rendering (CSR) provides a way to control the output/design of your fields and set of controls by leveraging HTML and JavaScript technologies for example how should the fields render in list views (edit, new or quick edit), search, list forms etc. Now, every field definition comes with JSLink property that can be overridden, ...


4

I believe with that technique you are creating a Field object for that list but it does not actually add a column, similar to adding columns to a Datatable(). For creating fields via code I typically go with //Add Column to list //GUID SPList.Fields.ADD(name,type,required); list.Fields.Add("Field Name", SPFieldType.Choice, false); //Get Field ...


4

One hint is to use AddRange() method to add array of strings as choices instead of adding choices with Add() one by one string[] Choices = { "choice1", "choice2", "choice3", "choice4", "choice5" }; col.Choices.AddRange(Choices);


4

You need to get the values into a collection object and then iterate through them and test it it is a group, if not assume it is a user, as follows: SPFieldUserValueCollection objUserFieldValueCol = new SPFieldUserValueCollection(web, listitem["UserGroupField"].ToString()); for (int i = 0; i < objUserFieldValueCol.Count; i++) { SPFieldUserValue ...


4

You can use the SPBuiltInFieldId.Author: listItem[SPBuiltInFieldId.Author] = new SPFieldUserValue(web, userId, userName); listItem.SystemUpdate(false);


4

In SharePoint 2013, just make a GET request in the following URL. /_api/Web/Lists/getbytitle('Name of the list')/Fields?$select=Title,InternalName In response, you will get all internal names and display names of the fields.


3

SPFieldChoice has a property named FieldRenderingControl. Using reflector you can find this code in the FieldRedneringControl property: .... switch (this.EditFormat) { case SPChoiceFormatType.Dropdown: control = new DropDownChoiceField(); break; case SPChoiceFormatType.RadioButtons: control = new RadioButtonChoiceField(); ...


3

Have a look at SPUtility.GetLocalizedString()


3

You can use jQuery to find the fields and apply css to them with something like: $("h3[class^='ms-standardheader']:contains('Assigned To')").css("font-weight", "Bold"); $("h3[class^='ms-standardheader']:contains('Description')").css("font-weight", "Bold");


3

http://www.pvle.be/2011/01/is-a-given-field-one-of-sharepoints-built-in-field/


3

Could be Double or Decimal or Integer. Use the ParseAndSetValue method to make sure it converts it to Double (see here http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldnumber.parseandsetvalue.aspx)


3

Minimum value is 1/1/1900. We have run into the minimum value issue with trying to date some documents from the 1800's. - Stackoverflow reference


3

To set a taxonomy field you should use TaxonomyFieldValue or TaxonomiFieldValueCollection You first need to find the term in your term store: TaxonomyField taxonomyField = item.Fields[field] as TaxonomyField; TaxonomyFieldValue taxValues = new TaxonomyFieldValue(taxonomyField); TaxonomySession session = new ...


3

You need to return the field value in HTML/Plain text format and update it. Here you go: SPSite site = new SPSite("http://site")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["YourList"]; SPListItem item= list.GetItemById(1); SPFieldMultiLineText multilineField = item.Fields.GetField(...


3

Found a proper javascript client object model solution for my problem: Here is the solution: this.listFields = list.get_fields(); ctx.load(this.listFields); And then in the function: onQuerySucceeded var fieldEnumerator = this.listFields.getEnumerator(); while (fieldEnumerator.moveNext()) { var field = fieldEnumerator.get_current(); ...


3

It sounds like you're using the ItemUpdated event. If you used ItemUpdating I believe you could modify the AfterProperties instead of performing a second update. This may be of use to you: NBSP: Event Receivers


3

In the second content type which you may have created for the ListB specify the Inherits attribute to False for ContentType property. An then in FieldRefs section rename the Status field. <ContentType ID="CTID" Name="CTName" Group="CTGroup" Description="CTDescription" Inherits="...


3

After some effort I converted it into PowerShell YAY! [Microsoft.SharePoint.SPList] $list = $web.Lists["Stakeholders Register"]; if(($list.Fields["Job Number"] -ne $null) -and ($list.Fields["Role within project"] -ne $null)) { $fieldReorderable = [string]::Empty; $fieldNonReorderable = [string]::Empty; $firstField = "...


3

You can use the Field type HTML. Here is a XML markup of that field: <Field ID="{E2CC0231-FA6C-4F90-839C-118C304DFCF1}" StaticName="PMediaDescription" Name="PMediaDescription" DisplayName="MediaDescription" Type="HTML" RichText="TRUE" RichTextMode="ThemeHtml" Group="Site Columns" UnlimitedLengthInDocumentLibrary ="TRUE" /> the real key here is: ...


3

Status workflow you can get using the following method public string GetWorkflowStatus(SPListItem item, String workFlowName) { SPWorkflowManager manager = item.Web.Site.WorkflowManager; foreach (SPWorkflow instance in manager.GetItemWorkflows(item)) { if (instance.ParentAssociation.Name == workFlowName) { foreach (...



Only top voted, non community-wiki answers of a minimum length are eligible