We have a lot of requests form clients about duplication of existing Sitefinity forms.
Please find a sample showing how to duplicate a specific form programmatically:
In the code we get an existing form and duplicate its controls and create a new form. You could change the name and title of the form to be different than the one we are using above. Execute the form in a new web form, created in Visual Studio.
Note that the sample works in monolingual environment.
Please find a sample showing how to duplicate a specific form programmatically:
protected void Page_Load(object sender, EventArgs e) { var fromManager = FormsManager.GetManager(); //Get an existing form
var firstForm = fromManager.GetForms().Where(f => f.Title == "Test").FirstOrDefault();
if (firstForm.LockedBy != null) { fromManager.UnlockForm(firstForm.Id, false); }
var firstDraft = fromManager.EditForm(firstForm.Id); //Duplicate the form DuplicateForm(firstForm.Title, firstDraft, fromManager); fromManager.Lifecycle.CheckIn(firstDraft); } void DuplicateForm(string title, FormDraft draftToDuplicate, FormsManager receivingManager) { var dateString = DateTime.Now.ToString("MMddHHmm"); var name = "sf_adave" + "_" + dateString; var formManager = receivingManager; //Create a new form var newForm = formManager.CreateForm(name); newForm.Title = title + "_" + dateString; var draft = formManager.EditForm(newForm.Id); var master = formManager.Lifecycle.CheckOut(draft); formManager.CopyControls(draftToDuplicate.Controls, master.Controls); master.SuccessMessage = draftToDuplicate.SuccessMessage; master.Owner = draftToDuplicate.Owner; master.LastModified = DateTime.Now; foreach (var control in master.Controls) { control.Published = false; } master = formManager.Lifecycle.CheckIn(master); formManager.Lifecycle.Publish(master); formManager.SaveChanges(true); }In the code we get an existing form and duplicate its controls and create a new form. You could change the name and title of the form to be different than the one we are using above. Execute the form in a new web form, created in Visual Studio.
Note that the sample works in monolingual environment.