I'm trying to write script (in C#, using Server Object Model) which gets all lists (lists are as-is, no alternation is allowed) from SPWeb (SharePoint 2013) and fill them up with random information so I can stress test the site.

Anyway, I want to get fields which are displayed in (random) list's New Form. I tried exposing fields with SPField.ShowInNewForm property, but without luck (as far as I can tell, if I don't explicitly write in list's schema this property, it will return false, even if view is using this field in New Form). My second approach was to get all views tied to particular list, but I couldn't know which one of them is actually used in New Form.

Any help or tip is more then welcome.

EDIT: At the moment script is checking if SPField is required, but it's not really the solution I'm looking for (I'd like to get all fields present in New Form).

EDIT 2: Script should work even if Edit Form and New Form have different views (e.g. Title of item is shown in New Form view but not in Edit Form view).

  • This isn't an answer to your original question, but more of a question on what you are trying to 'stress' with your script. Server Object Model load testing isn't going to really give you any insight into how many users your site can handle. To estimate any real user load, you should either do some functional testing with a tool like selenium, or at least use the Client Object Model which will also account for things like network latency, http overhead, etc. You may already have considered this, but based on your question, I just wanted to throw that out there. – tyshock Dec 18 '13 at 17:47
  • @tyshock Idea is to use this script as payload in SPJob (that's why I need ServerOM) and as a utility script during development. And... I actually didn't know about Selenium. It isn't really what I need at the moment, however, It seems like neat tool - many thanks. Anyway, even if my approach to testing is not really the best approach, I'd still like to know how to solve this particular problem. – StupidOne Dec 18 '13 at 18:11

I think you can try the field property CanBeDisplayedInEditForm. Loop through the list fields and check this property like below:

foreach (SPField field in list.Fields)
    if (field.CanBeDisplayedInEditForm)


There doesn't seem to have an easy one way solution to this problem. You may need to use combination of field properties like CanBeDisplayedInEditForm , ShowInNewForm etc in the if condition to fix this issue.

  • If Edit Form and New Form are not using the same view (I actually do have one list which has separeted views), script would fail. – StupidOne Dec 18 '13 at 14:07
  • You could try perhaps modify if condition where you can also check properties like ShowInNewForm – Nadeem Yousuf Dec 18 '13 at 14:39
  • I'm leaning toward this approach, even if it wouldn't work if New and Edit forms are using two different views (where, for example, you have injected brand new view in one of the forms via SharePoint Designer). Could you, please, update your answer so I can Upvote it? – StupidOne Dec 18 '13 at 18:21

Another way is go through all lists then all content types in this lists, then all fields in this content types and check if field "ReadOnlyField" and if field is "Hidden"

  • I'm not sure how this could help me - if the list have fields which are neither ReadOnly nor Hidden and they don't show in New Form, script would write data which is not suppose to be written when item is created. – StupidOne Dec 18 '13 at 14:05
  • If you use client side solution for example js to hide inputs etc. for hiding fields it would be hard to get fields that visible in NewForm – Andrey Ungur Dec 18 '13 at 14:31
  • It's not JS, Edit and New Form are using different views. – StupidOne Dec 18 '13 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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