To add a list item in SharePoint 2007/2010 I currently use the following XML:
<Batch OnError='Continue' ListVersion="1">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="Title">anyTitle</Field>
<Field Name="Account_x0020_Name">SomeText</Field>
</Method>
</Batch>
Sometimes the internal name is not equal to the display name. For example here the DisplayName is "Account Name" but its internal name is "Account_x0020_Name".
Is there any way to create a new list item using the DisplayName instead of the internal name?
I've already tried using <Field DisplayName="Account Name">SomeText</Field> but that gives a SoapException.
Any Ideas?
You need to use the Internal Field Name. The easiest way to get it is via list/library settings, selecting the field and looking for the name in the URL.
Related
I am trying to pre-populate my SharePoint list using its List Instance in SharePoint hosted app with default data. And it seems to work for the below code.
<ListInstance ...>
<Data>
<Rows>
<Row>
<Field Name="URL">http://google.com, Project Link</Field>
</Row>
</Rows>
</Data>
But when i try to add the URL from list in my app it is not working.
<ListInstance ...>
<Data>
<Rows>
<Row>
<Field Name="URL">~appWebUrl/Lists/SiteImages/image.png, Project Link</Field>
</Row>
</Rows>
</Data>
What is the syntax for this?
I don't believe it is possible to use tokens like ~appWebUrl in xml list instance definition. I suggest just to put relative url, e.g.
<Field Name="URL">/Lists/SiteImages/image.png, Project Link</Field>
To set url field of the current web you can use the ~site. If you want it to be that of the parent site collection then use ~sitecollection
Modify your code as below:
<Field Name="URL">~site/Lists/SiteImages/image.png, Project Link</Field>
If the url is there in the parent site collection, use it as below:
<Field Name="URL">~sitecollection/Lists/SiteImages/image.png, Project Link</Field>
Reference - URL and tokens in SharePoint
I have a sharepoint list that contains a multiple lookup field. I would like to change the way its values are displayed (normaly you get links to chosen items like item1;item2;item3), so that I could for instance construct my own link to redirect me to the source list filtered by items chosen on this lookup.
I try to do that by creating a custom field by that is inheriting SPFieldLookup, but i'm a bit stuck since I can't don't know which method/property to override to change what is being displayed (if this is possible at all). Any help would be appreciated
I'd create a custom field type that inherits from SPFieldLookup. But instead of do the rendering server side I'd use a XSTL to render the field:
How to: Customize the Rendering of a Field on a List View
This way you do not have to implement a custom SPField class at all. You just have to create a custom field type definition that points to the OOTB SPLookupField.
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">CustomLookupField</Field>
<Field Name="TypeDisplayName">Custom Lookup Field</Field>
<Field Name="TypeShortDescription">Custom Lookup Field</Field>
<Field Name="FieldTypeClass">Microsoft.SharePoint.SPFieldLookup</Field>
<Field Name="ParentType">Lookup</Field>
</FieldType>
</FieldTypes>
I'm trying to extend the built-in Choice field type to include another piece of data: a correct answer. With this, users would be able to create their own tests directly within Sharepoint instead of having to use InfoPath or some other convoluted solution. I was hoping to just inherit the existing SPFieldChoice type and add one more custom property to hold an integer representing the correct answer from the choices entered.
I've got a FieldTestQuestion class that inherits from SPFieldChoice along with a pretty basic TestQuestionFieldControl class inheriting from RadioButtonChoiceField. My fldtypes_TestQuestionField.xml file:
<FieldTypes>
<FieldType>
<Field Name="TypeName">TestQuestion</Field>
<Field Name="ParentType">Choice</Field>
<Field Name="TypeDisplayName">Test Question (Multiple choice)</Field>
<Field Name="TypeShortDescription">Test Question (Multiple choice)</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowInColumnTemplateCreate">TRUE</Field>
<Field Name="FieldTypeClass">MyCustomFieldTypes.FieldTestQuestion,MyCustomFieldTypes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=****</Field>
<PropertySchema>
<Fields>
<Field Name="CorrectAnswer" DisplayName="Correct answer (line number)" Type="Integer">
<Default></Default>
</Field>
</Fields>
</PropertySchema>
</FieldType>
</FieldTypes>
Unfortunately, this is what renders when I try adding a column of this type:
(source: mudman.us)
No option to add the choices as with the Choice field type:
(source: mudman.us)
What do I need to put in my fldTypes_.xml to tell Sharepoint to either (a) use the existing custom properties for the Choice column and ADD the extra property I specified or (b) specifically define a multi-line text custom property?
It would appear the Choice input box is being created specifically for SPFieldChoice columns; one of many un-inheritable features. This means that you're unlikely to be able to persuade SharePoint to reproduce it for your custom field type.
My advice would be to go for option b), and create it yourself. I believe adding this to the <fields> element will do the trick:
<Field Name="ChoiceFix" DisplayName="Type each choice on a separate line:" Type="Note" />
Be warned that I haven't tested this solution reliability, and you may have to go down the spiky and unpleasant route of making your own Field Editor Control.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I have created a custom field type (say 'Sample') in SharePoint which is based on 'multiline text' field type. Now I have created a new column(say 'test') of type 'Sample' in a list. I created some list items.
I can edit the column value successfully from SharePoint UI (through edit form). But when I try to modify the value of 'test' column programatically for any list item, value of 'test' column for that list item becomes null/empty.
Any idea why this probem is occuring?? Below is the filedtypes xml that I am using
<?xml version="1.0" encoding="utf-8"?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">Sample</Field>
<Field Name="ParentType">Note</Field>
<Field Name="TypeDisplayName">Sample</Field>
<Field Name="TypeShortDescription">Sample</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowInListCreate">TRUE</Field>
<Field Name="ShowInSurveyCreate">TRUE</Field>
<Field Name="ShowInDocumentLibraryCreate">TRUE</Field>
<Field Name="ShowInColumnTemplateCreate">TRUE</Field>
<Field Name="FieldTypeClass">
SharePoint.Sample.FieldType, SharePoint.Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c5560aa45b5518dc
</Field>
<Field Name="FieldEditorUserControl">
/_controltemplates/FieldEditor.ascx
</Field>
<PropertySchema>
<Fields>
<Field Name="DisplayedListBoxProperty" DisplayName="DisplayedListBoxProperty"
Type="Text" Hidden="True">
<Default>"abc"</Default>
</Field>
</Fields>
</PropertySchema>
</FieldType>
</FieldTypes>
Code that I am using to edit:
SPSite site = new SPSite("site url")
SPWeb web = site.OpenWeb();
SPList list = web.Lists["MyList"];
SPListItem item = list.Items[0];
item["test"] = "xyz"; //becomes null after update
item["numCol"] = "34"; //Gets updated to new value 34 after update
web.AllowUnsafeUpdates = true;
item.Update();
One Important thing: This code runs in itemupdating eventhadler of another list.
With your code, there is problem with your Custom Field Type with "FieldTypeClass". Try this 'SharePoint.Sample.FieldType, SharePoint.Sample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c5560aa45b5518dc'
hope this will helps you.
Well I found the problem area. There is a function called GetValidatedString() which is used for any validation on the value. This function gets called even in case when you update value programmatically.
It was creating a problem.
I'm trying to create a solution package for a set of features within a SharePoint site. I want to create an instance of a generic list (using ListInstance in the element manifest) and add an additional column to it (since by default they only have a Title column) without having to go through activation code.
Is there a way to do this through CAML? So, far I'm sort of stuck with the idea of having to create a custom content type but that means I would have to have a separate feature that activates at the Site level to deploy the content type first.
I believe this is what you are looking for, snippets:<!--Add a field reference for the custom field.-->
<FieldRef
ID="{AD22016D-BC8B-4631-A0A3-5E84C6CFA7EC}"
Name="FavoriteColor"
Required="TRUE"
ShowInNewForm="TRUE"
ShowInEditForm="TRUE"/>
and then:
<Fields>
<Field
Type="Choice"
Name="FavoriteColor"
DisplayName="Favorite Color">
<CHOICES>
<CHOICE>Red</CHOICE>
<CHOICE>Green</CHOICE>
<CHOICE>Blue</CHOICE>
</CHOICES>
</Field>
</Fields>
Making sure it is added to the view<ViewFields>
<FieldRef Name="FavoriteColor"/>
</ViewFields>