Skip to content

Instantly share code, notes, and snippets.

@sitefinitySDK
Last active November 30, 2022 15:01
SF_10.1, SF_10.2, SF_11.0, SF_11.1, SF_11.2, SF_12.0, SF_12.1, SF_12.2, SF_13.0, SF_13.1, SF_13.2, SF_13.3, SF_14.0, SF_14.1, SF_14.2, SF_14.3 - https://docs.sitefinity.com/for-developers-get-formfield-content-links-from-submitted-form-responses
using System.Linq;
using Telerik.Sitefinity.Forms.Model;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Model.ContentLinks;
using Telerik.Sitefinity.Modules.Forms;
using Telerik.Sitefinity.Modules.Libraries;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Forms
{
public partial class FormsSnippets
{
public static void GetFormFieldContentLinksFromFormResponses(string formName, string formFieldName)
{
FormsManager formsManager = FormsManager.GetManager();
LibrariesManager librariesManager = LibrariesManager.GetManager();
//Get the Form by Name
var form = formsManager.GetForms().Where(f => f.Name == formName).SingleOrDefault();
//Get the FormEntries for that Form
var records = formsManager.GetFormEntries(form);
// Loop through all the response records for this form
foreach (FormEntry record in records)
{
//Use GetValue() to obtain the fields ContentLink array
var contentLink = record.GetValue<ContentLink[]>(formFieldName).FirstOrDefault();
if (contentLink != null)
{
var document = librariesManager.GetDocument(contentLink.ChildItemId);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment