title: ASP.NET MVC 5 - validation excel/csv files
body: <p>I'm developing a website that need to upload excel/csv files.</p>
  
  <p>There is a way to validation files from hackers e.g. ensure that the files not contains malicious code?</p>
  
  <p>Until now I have this:</p>
  
  <pre><code>public class ValidateFileAttribute : RequiredAttribute
  {
      private readonly decimal filesize = 10;//10 MB
      bool result = false;
      string[] supporteFilesdTypes = new[] { "csv", "xls", "xlsx" };
      public override bool IsValid(object value)
      {
          var file = value as HttpPostedFileBase;
          if (file == null)
          {
              return false;
          }
  
          var fileExt = Path.GetExtension(file.FileName).Substring(1).ToLower();
          switch (fileExt)
          {
              case "csv":
              case "xls":
              case "xlsx":
                  result = file.ContentLength &gt; (filesize * 1024);
                  break;
              default:
                  break;
  
          }
  
          return result;
      }
  }
  
  public class ManipulateFile
  {
      [ValidateFileAttribute]
      public HttpPostedFileBase FileUpload { get; set; }
  
      public ManipulateFile()
      {
  
      }
  }
  </code></pre>