本文整理汇总了C#中System.Web.HttpFileCollectionBase.GetMultiple方法的典型用法代码示例。如果您正苦于以下问题:C# HttpFileCollectionBase.GetMultiple方法的具体用法?C# HttpFileCollectionBase.GetMultiple怎么用?C# HttpFileCollectionBase.GetMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpFileCollectionBase
的用法示例。
在下文中一共展示了HttpFileCollectionBase.GetMultiple方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsValidForm
/// <summary>
/// Determines whether a form is valid or not.
/// </summary>
/// <param name="form">The form.</param>
/// <param name="collection">The collection.</param>
/// <param name="manager">The manager.</param>
/// <returns>true if form is valid, false otherwise.</returns>
protected virtual bool IsValidForm(FormDescription form, FormCollection collection, HttpFileCollectionBase files, FormsManager manager)
{
this.SanitizeFormCollection(collection);
var behaviorResolver = ObjectFactory.Resolve<IControlBehaviorResolver>();
foreach (var control in form.Controls)
{
if (control.IsLayoutControl)
continue;
Type controlType;
if (control.ObjectType.StartsWith("~/"))
controlType = FormsManager.GetControlType(control);
else
controlType = TypeResolutionService.ResolveType(behaviorResolver.GetBehaviorObjectType(control), true);
if (!controlType.ImplementsGenericInterface(typeof(IFormElementController<>)))
continue;
var controlInstance = manager.LoadControl(control);
var controlBehaviorObject = behaviorResolver.GetBehaviorObject(controlInstance);
if (controlBehaviorObject is IFormFieldController<IFormFieldModel>)
{
var formField = (IFormFieldController<IFormFieldModel>)controlBehaviorObject;
var multipleFiles = files.GetMultiple(formField.MetaField.FieldName);
object fieldValue;
if (multipleFiles != null && multipleFiles.Count() > 0)
{
fieldValue = (object)multipleFiles;
}
else
{
collection[formField.MetaField.FieldName] = collection[formField.MetaField.FieldName] ?? string.Empty;
fieldValue = (object)collection[formField.MetaField.FieldName];
}
if (!formField.Model.IsValid(fieldValue))
return false;
}
else
{
var formElement = (IFormElementController<IFormElementModel>)controlBehaviorObject;
if (!formElement.IsValid())
return false;
}
}
return true;
}
示例2: TrySubmitForm
/// <inheritDoc/>
public virtual SubmitStatus TrySubmitForm(FormCollection collection, HttpFileCollectionBase files, string userHostAddress)
{
var manager = FormsManager.GetManager();
var form = manager.GetForm(this.FormId);
var formEntry = new FormEntryDTO(form);
var formSubmition = new FormsSubmitionHelper();
if (!this.ValidateFormSubmissionRestrictions(formSubmition, formEntry))
return SubmitStatus.RestrictionViolation;
if (!this.IsValidForm(form, collection, files, manager))
return SubmitStatus.InvalidEntry;
var formFields = new HashSet<string>(form.Controls.Select(this.FormFieldName).Where((f) => !string.IsNullOrEmpty(f)));
var postedFiles = new Dictionary<string, List<FormHttpPostedFile>>();
for (int i = 0; i < files.AllKeys.Length; i++)
{
if (formFields.Contains(files.AllKeys[i]))
{
postedFiles[files.AllKeys[i]] = files.GetMultiple(files.AllKeys[i]).Where(f => !f.FileName.IsNullOrEmpty()).Select(f =>
new FormHttpPostedFile()
{
FileName = f.FileName,
ContentLength = f.ContentLength,
ContentType = f.ContentType,
InputStream = f.InputStream
}).ToList();
}
}
var formData = new List<KeyValuePair<string, object>>(collection.Count);
for (int i = 0; i < collection.Count; i++)
{
if (formFields.Contains(collection.Keys[i]))
{
formData.Add(new KeyValuePair<string, object>(collection.Keys[i], collection[collection.Keys[i]]));
}
}
formEntry.PostedData = formData;
formEntry.Files = postedFiles;
formSubmition.Save(formEntry);
return SubmitStatus.Success;
}