I'm trying to add content types into a library list, in order to make "Visible on New" option ticked.

Firstly I enabled contenttypes in the library, then I want to do this:

SPFolder rootFolder = list.RootFolder;
IList<SPContentType> ctList = rootFolder.ContentTypeOrder;
rootFolder.UniqueContentTypeOrder = ctList;

But this line IList<SPContentType> ctList = rootFolder.ContentTypeOrder; keeps throwing unexpected error:

Error occurred in deployment step 'Activate Features': 
Unhandled exception was thrown by the sandboxed code wrapper's Execute 
method in the partial trust app domain: An unexpected error has occurred.

I'm not sure if this error is related to the sandbox solution.

Related question: Content Types not visible under New Button


It's related to the sandbox, because you cannot use SPFolder.ContentTypeOrder and SPFolder.UniqueContentTypeOrder in sandbox :\

Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Available in Sandboxed Solutions: No


If it's just to order, the code posted as an answer by James in this question might work.

  • Thanks! However I'm not ordering... I just want to enable the CT on New button – wceo Jan 16 '13 at 9:17

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.