0

I can create workspace by using this code:

var myWorkspace = Content.CreateNew("/Root/Sites/Default_Site", "Workspace", "MyWorkspace"); await myWorkspace.SaveAsync();

How to set myWorkspace using dotnet client to have File in 'Allowed child types'?

Rezkar Js
  • 3
  • 2

1 Answers1

0

AllowedChildTypes is a field of the workspace content, so you can set its value like other field values. The value should be an array of strings (array of content type names).

content["AllowedChildTypes"] = ["File"];
await content.SaveAsync();

There's also an OData action for adding a content type to a content's AllowedChildTypes, its name is AddAllowedChildTypes and it should get a contentType array (string array of content type names) as parameter.

   dynamic workspace = await Content.LoadAsync(workspace);

    Task<dynamic> task = workspace.AddAllowedChildTypes(new {contentTypes = ["File"]});
    var result = await task;

https://community.sensenet.com/docs/built-in-odata-actions-and-functions/#add-types-to-allowed-child-types-action

Aniko Litvanyi
  • 2,109
  • 1
  • 21
  • 25
  • @RezkarJs I put some examples to my answer – Aniko Litvanyi Aug 29 '19 at 15:09
  • Sorry, it just replace default AllowedChildTypes with File only, i need default + File, how? – Rezkar Js Sep 12 '19 at 09:01
  • @RezkarJs did you try the second example? The AddAllowedChildTypes action do not replace the type list, just add the one you've set as parameter – Aniko Litvanyi Sep 12 '19 at 09:05
  • It's invalid code, i've tried this code > Task task = workspace.AddAllowedChildTypes(new { contentTypes = new string[] { "File" } }); But default AllowedChildTypes just replaced with File only. – Rezkar Js Sep 12 '19 at 09:59