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


12

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


10

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


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


6

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


5

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


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


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

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


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

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


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


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

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


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 have exactly same problem in sharepoint foundation 2010. So far i think it is bug in sharepoint. FormFields some how changes listid and itemid in contextes of other controls when Formfield is rendered. Note that this happens only when it rendered, so if you put two formfields on one page but one of them have visible attribute=false, other formfield will be ...


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

There is an explanation how to fix your problem, but I'm not sure that this solution is good, because you should change sharepoint fiels. I think that the best way is to change logic of your application.


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

The Group property is a string, it's used to Group fields on the Site Columns page. If you do this through the UI it provides a default of "Custom Columns". Typically I use something descriptive for the particular customer and project, e.g. "{Customer}: {Project}"


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

a shot in the dark here, you can try this that iv just put together? using (SPSite site = new SPSite("url goes here")) { using (SPWeb oWebsite = site.OpenWeb()) { SPList oList = oWebsite.Lists["discussion list name"]; SPListItem item = oList.GetItemById(12); ...


2

If there is a possibility of an AD group in there and you would like to handle that, have a look at my solution: public static List<string> GetUserLogins(SPListItem item) { //create empty list of usernames List<string> Users = new List<string>(); //retrieve user value collection from the "AssignedTo" field and iterate ...



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