Import Forms submission data automatically

  • Updated

The code snippet below is used to import multiple submission data to form for testing.

var ddsSubmission = new DdsPermanentStorage();
//this guid can be get from  html tag is generated in container page
//use inspect element tool of browser and click to this form, we can see the html like below:
//<form method="post" novalidate="novalidate" data-f-metadata="" enctype="multipart/form-data" class="EPiServerForms ValidationSuccess" data-f-type="form" id="a8f68ee9-882a-4783-b39c-345060fbaf47">
var formIdentity = new FormIdentity(Guid.Parse("a8f68ee9-882a-4783-b39c-345060fbaf47"), "no");
var submission = new Submission();
for (int i = 0; i <= 100; i++)
   submission.Id = string.Empty;
   submission.Data = new Dictionary<string, object>();
   //form elements...
   //the number is form element's content id in cms
   submission.Data.Add("__field_54", String.Concat("Value", i));
   //generic data fields
   submission.Data.Add("SYSTEMCOLUMN_SubmitTime", DateTime.Now.ToString());
   submission.Data.Add("SYSTEMCOLUMN_SubmitUser", "admin"); 
   //submit username
   submission.Data.Add("SYSTEMCOLUMN_FinalizedSubmission", true);
   submission.Data.Add("SYSTEMCOLUMN_Language", "no"); 
   //language code
   submission.Data.Add("SYSTEMCOLUMN_HostedPage", "22"); 
   //the id of the form's container page
   ddsSubmission.SaveToStorage(formIdentity, submission);