OneDrive: Hide custom fields on document Properties page

Hello,

I tried to add several custom fields for file entities in OneDrive for Business. They should be hidden from end users completely. I've created a custom fields for list called "Documents" using SharePoint CSOM:

                    var list = context.Web.Lists.GetByTitle("Documents");
                    ClientObjectPrototype allFields = list.Fields.RetrieveItems();
                    allFields.Retrieve(FieldPropertyNames.Title, FieldPropertyNames.InternalName);

                    context.ExecuteQuery();
                    if (!list.Fields.Any(f => f.InternalName == "Os33_x002e_CustomProperty5"))
                    {
                        list.Fields.AddFieldAsXml(
                            "<Field Type='Number' Name='Os33.CustomProperty5' Viewable='false' " +
                            "ShowInDisplayForm ='false' ShowInEditForm='false' ShowInFileDialog='false' " +
                            "ShowInFileDlg='false' ShowInListSettings='false' ShowInNewForm='false' " +
                            "ShowInVersionHistory='false' ShowInViewForms='false' " +
                            "Required='false' Hidden='true' Decimals='0' Min='0' DisplayName='Os33.CustomProperty5'><Default>0</Default></Field>",
                            false,
                            AddFieldOptions.AddToAllContentTypes);
                       

                        list.Update();
                        context.ExecuteQuery();
                    }
But editor for field is shown on the file's Property page. How to hide this field?


June 29th, 2015 12:06pm

In order to hide the fields, you could use SetShowInDisplayForm, SetShowInEditForm and SetShowInNewForm.

Field customField = list.Fields.GetByInternalNameOrTitle("<customfieldnameortitle>");
context.ExecuteQuery();

//customField.ReadOnlyField = false;
//customField.Hidden = false;
customField.SetShowInDisplayForm(false);
customField.SetShowInEditForm(false);
customField.SetShowInNewForm(false);
                       

customField.Update();

context.ExecuteQuery();

You could also use the Hidden and Read Only properties as per your requirements.


  • Edited by Jibin Johnson 5 hours 56 minutes ago incorrect object name in the code
Free Windows Admin Tool Kit Click here and download it now
June 29th, 2015 9:40pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics