Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
my class :

C#
public class uploadImageMahsolat
    {
        [FileTypes("jpg,jpeg,png")]
        [Required(ErrorMessage = "its  Required.")]
        public HttpPostedFileBase Fileimg { get; set; }


        [FileTypes("jpg,jpeg,png")]
        [Required(ErrorMessage = "its  Required .")]
        public ICollection<HttpPostedFileBase> FileUpload900 { get; set; }

    }




C#
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 fileExt = System.IO.Path.GetExtension((_value as HttpPostedFileBase).FileName).Substring(1);





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


but it show error "Object reference not set to an instance of an object" on bold line
Posted
Updated 28-Dec-13 5:31am
v2

1 solution

Refer Object reference not set to an instance of an object[^].

This error happens when you try to use a property or call a method of an object that is null.
 
Share this answer
 
Comments
Member 8454063 28-Dec-13 11:48am    
no , i trace my code . it gets image . _value is not null . but _value as HttpPostedFileBase is null . why?
I am not a MVC guy, but if you can search on Google about it, you will definitely get solutions for sure.
I guess you are trying to use the class, but you have not initialized its object. So, research on it.

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