If I create a form in a site template using Forms Designer for SharePoint on Office 365, will the form be available in all sites created which are based on that template? I had set up a site template using PowerApps, only to find that PowerApps doesn’t tie into the site template and so any new sites created revert to the standard SharePoint form.
Then, design a form or open an existing one that you want to provision in Plumsail Forms. Export it to XFDS file with Export button in the ribbon.
Then, use the code below to provision the form as an Edit one to an arbitrary site/list in SharePoint:
static void Main(string[] args)
{
var login = "your login";
var password = GetSecureString("your password");
var webUrl = "SharePoint site 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("ListName");
var cts = list.ContentTypes;
ctx.Load(list);
ctx.Load(cts);
ctx.ExecuteQuery();
// Specify a content type which form you want to replace
var contenType = cts.FirstOrDefault(ct => ct.Name == "Item");
var forms = new FormsDesigner.SharePoint.FormsManager(ctx, list.Id, contenType.Id.ToString());
// Load your XFDS-file
var layout = XDocument.Load("Item_Edit.xfds");
FormsDesigner.SharePoint.Config.PlumsailServicesBaseAddress = new Uri("https://forms.plumsail.com/");
Task.Run(async () =>
{
var compiledForm = await CompileForm(layout);
// The form will replace a default Edit form in the target list
forms.GenerateForms(Guid.Empty, FormsDesigner.Data.SharePoint.FormTypes.Edit, layout, compiledForm);
}).Wait();
}
}
private static async Task<CompiledForm> CompileForm(XDocument layout)
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("https://forms.plumsail.com/");
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await httpClient.PostAsJsonAsync($"api/sharepoint", layout);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsAsync<CompiledForm>();
}
private static SecureString GetSecureString(string s)
{
SecureString result = new SecureString();
foreach (char c in s.ToCharArray())
{
result.AppendChar(c);
}
return result;
}
Dear Marko,
The answer posted by Dmitry refers to Plumsail Forms for SharePoint Online Modern UI. If you are using Plumsail Forms, it’s going to work with Office365 SharePoint as it’s the only platform supported currently.
If you are using Forms Designer instead, then this code wouldn’t work. Let us know if this is the case.