public override void Submitted(FormSubmittedEventContext context)
        {
            foreach (var element in context.Form.Elements)
            {
                var fileFieldElement = element as FileField;

                if (fileFieldElement==null)
                    continue;

                var postedFileValue = context.ValueProvider.GetValue(fileFieldElement.Name);

                if (postedFileValue == null)
                    return;

                var postedFile = ((System.Web.HttpPostedFileBase[])(postedFileValue.RawValue))[0];

                var path = Path.Combine(fileFieldElement.FilePath, Path.GetFileName(postedFile.FileName));

                if (fileFieldElement.GenerateUnique)
                {
                    int count = 1;
                    var pathPattern = Path.Combine(fileFieldElement.FilePath, string.Format("{0}_{{0}}{1}", Path.GetFileNameWithoutExtension(postedFile.FileName), Path.GetExtension(postedFile.FileName)));
                    while (File.Exists(string.Format(pathPattern, count)))
                    {
                        count++;
                    }

                    path = string.Format(pathPattern, count);
                }

                context.Values[fileFieldElement.Name + ":size"] = postedFile.ContentLength.ToString();
                context.Values[fileFieldElement.Name] = path;
                fileFieldElement.PostedValue = path;
            }
        }
Beispiel #2
0
        public override void Submitted(FormSubmittedEventContext context)
        {
            foreach (var element in context.Form.Elements.Flatten())
            {
                var fileFieldElement = element as FileField;
                if (fileFieldElement == null)
                {
                    continue;
                }

                var postedFileValue = context.ValueProvider.GetValue(fileFieldElement.Name);
                if (postedFileValue == null)
                {
                    continue;
                }

                var postedFiles = (HttpPostedFileBase[])postedFileValue.RawValue;
                if (postedFiles == null && postedFiles.Length != 1)
                {
                    continue;
                }

                var folderPath   = _tokenizer.Replace(fileFieldElement.FilePath, new { });
                var uniqFileName = _mediaLibraryService.GetUniqueFilename(folderPath, postedFiles[0].FileName);
                var path         = _storageProvider.Combine(fileFieldElement.FilePath, uniqFileName);

                context.Values[fileFieldElement.Name + ":size"] = postedFiles[0].ContentLength.ToString();
                context.Values[fileFieldElement.Name]           = path;
                fileFieldElement.PostedValue = path;
            }
        }
        public override void Submitted(FormSubmittedEventContext context)
        {
            foreach (var element in context.Form.Elements)
            {
                var fileFieldElement = element as FileField;

                if (fileFieldElement == null)
                {
                    continue;
                }

                var postedFileValue = context.ValueProvider.GetValue(fileFieldElement.Name);

                if (postedFileValue == null)
                {
                    return;
                }

                var    postedFile = ((System.Web.HttpPostedFileBase[])(postedFileValue.RawValue))[0];
                string mediaPath  = System.Web.Hosting.HostingEnvironment.MapPath("~/Media/Default") + "/";

                var path = Path.Combine(mediaPath + fileFieldElement.FilePath.TrimEnd('/') + "/", Path.GetFileName(postedFile.FileName));

                if (fileFieldElement.GenerateUnique)
                {
                    int count       = 1;
                    var pathPattern = Path.Combine(mediaPath + fileFieldElement.FilePath.TrimEnd('/') + "/", string.Format("{0}_{{0}}{1}", Path.GetFileNameWithoutExtension(postedFile.FileName), Path.GetExtension(postedFile.FileName)));
                    while (File.Exists(string.Format(pathPattern, count)))
                    {
                        count++;
                    }

                    path = string.Format(pathPattern, count);
                }

                context.Values[fileFieldElement.Name + ":size"] = postedFile.ContentLength.ToString();
                context.Values[fileFieldElement.Name]           = path;
                fileFieldElement.PostedValue = path;
            }
        }
 public virtual void Submitted(FormSubmittedEventContext context) {}
Beispiel #5
0
 public virtual void Submitted(FormSubmittedEventContext context)
 {
 }