当前位置: 首页>>代码示例>>C#>>正文


C# HttpFileCollectionBase.GetMultiple方法代码示例

本文整理汇总了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;
        }
开发者ID:RichiL,项目名称:feather-widgets,代码行数:56,代码来源:FormModel.cs

示例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;
        }
开发者ID:RichiL,项目名称:feather-widgets,代码行数:48,代码来源:FormModel.cs


注:本文中的System.Web.HttpFileCollectionBase.GetMultiple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。