我正在尝试使用网络表单在sitecore 8中进行文件上传验证,但它不起作用请向我推荐解决方案。这是我的代码。
library(bizdays)
load_rmetrics_calendars(2014)
mutate(df2,
nbd_time=following(time_seq, 'Rmetrics/NERC'),
nbd_time=ifelse(nbd_time==time_seq, offset(time_seq, 1, 'Rmetrics/NERC'), nbd_time),
nbd_time=as.Date(nbd_time, origin="1970-01-01"),
nbddow=wday(nbd_time, label=TRUE))
创建RestrictedUploadField类
namespace Test.Web.WFFM
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class LimitFileSizeAttribute : DynamicValidationBase
{
private const string FileSizeLimitKey = "filesizelimit";
private const string ErrorMessageKey = "filesizelimiterror";
protected override ValidationResult ValidateFieldValue(IViewModel model, object value, ValidationContext validationContext)
{
// Required attribute should handle null value
if (value == null)
{
return ValidationResult.Success;
}
var fileBase = value as HttpPostedFileBase;
if (fileBase == null)
{
return new ValidationResult(ErrorMessage);
}
var fileUploadField = validationContext.ObjectInstance as FileUploadField;
var limit = GetLimit(fileUploadField);
if (limit == -1) // Limit not set
{
return ValidationResult.Success;
}
if (fileBase.ContentLength > limit)
{
return new ValidationResult(GetErrorMessage(fileUploadField));
}
return ValidationResult.Success;
}
private static int GetLimit(IViewModel field)
{
if (field == null || !field.Parameters.ContainsKey(FileSizeLimitKey))
{
return -1;
}
var parameter = field.Parameters[FileSizeLimitKey];
int intValue;
if (int.TryParse(parameter, out intValue))
{
return intValue;
}
return -1;
}
private string GetErrorMessage(IViewModel field)
{
if (field != null && field.Parameters.ContainsKey(ErrorMessageKey))
{
return field.Parameters[ErrorMessageKey];
}
return ErrorMessage;
}
}}
在sitecore中创建自定义验证并添加“参数”和“本地化参数”
创建自定义字段类型“Restricted File Upload”,在“验证”字段中添加验证,添加“参数”和“本地化参数”。