Hi, I am following the guide on form provisioning (SP 2019) and am getting the attached error. The only things I am changing from the guide are the variables: login, password, ListTitle, formPath and webUrl.
I'm a bit confused, is this not declared as "contentType" further up and is "Item"
I have tried using "Item" but that does not work either? As it's a standard list, the only content type is Item?
var listTitle = "FormsList";
// NAME OF THE CONTENT TYPE:
var contentType = "Item";
// PATH TO THE EXPORTED FORM:
var formPath = "c:\\provision\\Item_Edit_WIP2020_V2_OCT2020.xfds";
// URL OF THE NEW SITE:
var webUrl = "https://url";
using (var ctx = new ClientContext(webUrl))
{
ctx.Credentials = new SharePointOnlineCredentials(login, password);
// Specify a list which form you want to replace
var list = ctx.Web.Lists.GetByTitle(listTitle);
var cts = list.ContentTypes;
ctx.Load(list);
ctx.Load(cts);
ctx.ExecuteQuery();
// Specify a content type which form you want to replace
var cType = cts.FirstOrDefault(ct => ct.Name == contentType);
var forms = new FormsManager(ctx, list.Id, cType.Id.ToString());
var layout = XDocument.Load(formPath);
// THE FORM WILL REPLACE A DEFAULT NEW FORM IN THE TARGET LIST:
forms.GenerateForms(Guid.Empty, FormTypes.New, layout);
I have got this working by amending to the following:
Uri hubUri = new Uri("https:/fullurl");
using (var ctx = new ClientContext(webUrl))
{
//ctx.Credentials = new SharePointOnlineCredentials(login, password);
var test = new SPClientProvider(0,login, passwordasstring);
// Specify a list which form you want to replace
var list = ctx.Web.Lists.GetByTitle(listTitle);
var cts = list.ContentTypes;
ctx.Load(list);
ctx.Load(cts);
ctx.ExecuteQuery();
// Specify a content type which form you want to replace
var cType = cts.FirstOrDefault(ct => ct.Name == "Item");
var forms = new FormsManager(test, hubUri, list.Id, cType.Id.ToString());