Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Determines permitted mime types from the Secure File Upload Field
private List<FileType> DeterminePermitedMimeTypes()
{
var fileTypes = new List<FileType>();
if (FieldItem != null)
{
var itemIds = new List<string>();
var regexSelectedValue = new Regex(@"<selectedvalue>(.*?)</selectedvalue>".ToLower());
var selectedValueNodes = regexSelectedValue.Matches(FieldItem["Parameters"].ToLower());
if (selectedValueNodes.Count > 0)
{
foreach (Match selectedValueNode in selectedValueNodes)
{
var regexItems = new Regex(@"<item>(.*?)</item>".ToLower());
var itemNodes = regexItems.Matches(selectedValueNode.ToString());
itemIds.AddRange(from Match itemNode in itemNodes
where itemNode.Groups[1] != null
&& !string.IsNullOrEmpty(itemNode.Groups[1].Value)
&& TryParseGuid(itemNode.Groups[1].Value)
select itemNode.Groups[1].Value);
}
if (itemIds.Any())
{
var fileTypeItems = itemIds.Select(i => Sitecore.Context.Database.GetItem(i));
fileTypes = fileTypeItems.Select(i => new FileType(i)).ToList();
}
}
}
return fileTypes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment