Tag Info

Hot answers tagged

17

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 ...


9

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 ...


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, ...


8

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();


5

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"."


5

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 ...


4

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) ...


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

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

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

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 ...


2

One approach might be Gunnar Peipman's - use reflection to bypass the SetCustomProperty field entirely. It has worked well for me a few times.You may need to serialize/deserialize data in these prope private void SetFieldAttribute(string attribute, string value) { Type baseType; BindingFlags flags; MethodInfo mi; baseType = typeof(MyCustomField); flags = ...


2

I have tried this code snippet (from console application): using(SPSite site = new SPSite("http://mycoolsite")) { using(SPWeb web = site.OpenWeb()) { SPList list = web.Lists["My List"]; SPField fldTitle = list.Fields["Title"]; fldTitle.Required = false; fldTitle.Title = "New title"; ...


2

I recently had this problem myself; the only difference being that I was using a CAML query. If your code above is abridged and you were too, this may be of use to you. The problem boiled down to two issues: a) I hadn't added one of the columns to the ViewFields XML, so the field wasn't in the SPListItem at all. b) Once I did add it, I had to set my new ...


2

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 = ...


2

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


2

To my knowledge dates are stored as sequential serial numbers so they can be used in calculations. By default, December 31 1899 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after January 1, 1900. Time also as part of a date value is also represented as decimal number (for example, 12:00 PM is represented as 0.5 ...


2

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: ...


2

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 ...


1

You'll need to have all the values as either properties (@columnname) or as parameters ($parameterOfColumnname) and use the XSLT method sum(). <xsl:variable name="multiplyingValue"> <xsl:value-of select="@multiplyingValue" /> </xsl:variable> <xsl:variable name="firstNumber"> <xsl:value-of select="@firstNumber" /> ...


1

Lookup fields (which user extends) supports AllowMultipleValues. Then you can do: var multi = field is SPFieldMultiChoice || (field is SPFieldLookup && (field as SPFieldLookup).AllowMultipleValues); Same for Taxonomy


1

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(); ...


1

I don't think what you're attempting to do is possible with the native SharePoint field types. Normally Custom Field Types define a FieldEditorUserControl that lives in %SharePoint folder%/TEMPLATE/CONTROLTEMPLATES. This defines what to show to the users when adding/editing a field type. Some of the native field types have controls in there ...


1

Use the build-in webdeveloper tool in the browser (F12) and inspect the element. I'm pretty sure it's just border around the contextmenu div. Add the below to your CSS file and brand it. Beware that this will change it for all contextmenus on your site using your CSS file, so you might want to narrow it down to your custom list. Over all: .s4-ctx{ } ...


1

Having an SPField there is no direct way of finding out if it has been defined in the List, ListDefinition or as a Site Column. All fields created by the user in the UI will have the SourceId set to the ID of the list. But when you define a site column or a field in a list definition you can set that to anything. If you "only" want to find out if the field ...


1

Ok, I've solved it. I am not sure why, but when I use User1 account, I need to explicitly specify the fields I want to get when I am retrieving SPItem object. So, previously I have had instantiated the item object with the following line: this.item = this.list.Items.GetItemById(Convert.ToInt32(itemId, CultureInfo.InvariantCulture)); But, in order to have ...


1

The problem appears to be with reuse of the SPWeb (wrapped in SPContext) used by ItemContext and RenderContext I had a number of different problems including the one here, they all finally went away when I created my own SPWeb every time I need one. using (SPSite site = new SPSite(list.ParentWeb.Url)) { using (SPWeb web = site.OpenWeb()) { ...


1

Here's how it's done in SharePoint 2010: public ICollection<SPFieldTemplateUsage> ListsFieldUsedIn() { List<SPFieldTemplateUsage> list = new List<SPFieldTemplateUsage>(); using (SPSqlCommand command = new SPSqlCommand()) { using (SqlDataReader reader = this.GetSqlDataForPushdown(command)) { if ...


1

The string property you are looking for is SPField.AuthoringInfo. Unfortunately this is a readonly property. But the value of this property is stored in the SchemaXml property of the field. So you can set this value by altering the SchemaXml. using (SPSite s = new SPSite("http://MyWeb")) { using (SPWeb web = s.OpenWeb()) { SPList l = ...


1

Short answer: No. The only (out of the box) ways to do this are: Lookup field (PRO: behaves as a choice field when rendered) (CON: only works within 1 site only) Managed metadata, adding the value as a synonym (PRO: works everywhere) (CON: is type ahead, so looks different from choice field)



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