开发者

Programatically updating SharePoint custom field type column value [closed]

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜