Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi
i use below code for validate HttpPostedFileBase .

class :

C#
 public class uploadImage
    {

        [FileTypes("jpg,jpeg,png")]
        public HttpPostedFileBase File128 { get; set; }
     }

public class FileTypesAttribute : ValidationAttribute
    {

       
        private readonly List<string> mTypes;

        public FileTypesAttribute(string _types)
        {
            mTypes = _types.Split(',').ToList();
        }

        public override bool IsValid(object _value)
        {
            if (_value == null)
            {
                return true;
            }

         
         
       
            var st = (_value as HttpPostedFileBase).FileName;
            var fileExt = System.IO.Path.GetExtension((_value as HttpPostedFileBase).FileName).Substring(1);

            return mTypes.Contains(fileExt, StringComparer.OrdinalIgnoreCase);
        }

  
    }


if i use IEnumerable<httppostedfilebase> in my class , how can check validate of it ?

C#
   public class uploadImage
    {
       [FileTypes("jpg,jpeg,png")]

        public ICollection<HttpPostedFileBase> FileUpload900 { get; set; }
    }


    public class FileTypesAttribute : ValidationAttribute
    {

       
        private readonly List<string> mTypes;

        public FileTypesAttribute(string _types)
        {
            mTypes = _types.Split(',').ToList();
        }

        public override bool IsValid(object _value)
        {
            if (_value == null)
            {
                return true;
            }


           

               //how can check items of IEnumerable<HttpPostedFileBase>????
          
         


       
        }

      
    }
Posted
Updated 28-Dec-13 17:19pm
v3
Comments
Sergey Alexandrovich Kryukov 28-Dec-13 19:32pm    
What do you mean by "check validate", "check items"? What exactly do you need to do? Which IEnumerable object do you mean? The name of this interface is not mentioned anywhere in your code, so what is it?
—SA
Member 8454063 28-Dec-13 23:18pm    
"ICollection<httppostedfilebase> FileUpload900 " get some images . i want to check every item is image or not . my first code works for " HttpPostedFileBase File128 " correctly . but dose not work for "ICollection<httppostedfilebase>" . i don't know how can i browse it's items and check them .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900