Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created a new site column, a choice column with 5 values to pick from in a drop down list : 1, 2, 3, 4 (default value), 5

I then created a document content type using this column. The problem I am currently having is that when uploading a new document, I programmatically set the ControlMode of the baseFieldControl to SPControlMode.Display for certain users that should not be able to modify this column's value but should still be able to upload new document to the library. On the edit form, the value that is displayed is "4" which is normal as it is the defalut value, but once you save, if you go have a look the items properties, the saved value is "1". If you do the same test but using radio buttons it doesn't even save a value, not even the first one.

So basically all I want is to be able to set a field "readonly" on the edit form when adding a new document but I want the default value to be saved properly.

Thanks for any help you can provide on that issue.

Alex

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

If you want to use your BaseFieldControl with the Display Mode and set a value, you must set the value before setting the ControlMode.

You may find a different workaround Here

share|improve this answer
    
Hey thanks for answer. Unfortunately I also found that post while searching on the web but everything he mentions applies when you create a custom field in visual studio, which is not my case. I simply created a choice column in sharepoint 2010. And I override the CreateChildControls of the EditForm in order to set the ControlMode of certain fields. On that post, the code to solve this issue must be placed in the OnInit() of the custom field which I don't have. I just don't understand why the default value is not saved even if the field's controlmode is set to display. –  Alex Aug 17 '12 at 16:10
    
Hi explanation is : "...when the field control mode is set to display on the new form .. the value of the PreviewValueTyped property of the related field is displayed......The source of the issue seems to be is that the ItemFieldValue property and the ListItemFieldValue property of the BaseFieldControl return the value of the PreviewValueTyped if the ItemId property is zero, that is the case for a new item." I think Event receiver can solve ur problem, on ItemUpdating if the ControlMode is Display for the BaseFieldControl then set the value 4 from code –  Diptarag Aug 17 '12 at 16:23
    
That would make sense indeed! Thanks for the suggestion, I'll have a look at what I can do in ItemUpdating right now! –  Alex Aug 17 '12 at 16:32
    
Please check and kindly let me know if it worked –  Diptarag Aug 17 '12 at 16:43
    
I finally found a way to do it in ItemUpdating that I think wont screw the way things work when simply editing a document's properties. Here is what I did : SPListItem spListItem = properties.ListItem; foreach (SPField field in spListItem.Fields) { if (field.Type == SPFieldType.Choice && field.DefaultValue != null) { properties.AfterProperties[field.InternalName] = properties.BeforeProperties[field.InternalName] ?? field.DefaultValue; } } I still have a lot of testing to do as there are many cases that will run through this code, but I believe I am on the right track now. –  Alex Aug 22 '12 at 19:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.