views:

396

answers:

1

I want to verify the type of the uploaded file, that's how I do it:

 [AcceptVerbs(HttpVerbs.Post)]
        public ViewResult GetDataFromFile()
        {
            var file = Request.Files.Get(0);
...
            if (file.ContentType != "text/csv")
            {
                ModelState.AddModelError("FileInput.File", "The file uploaded is not in the correct format, please upload a csv file");
                return View("Index", new CandidateBulkInsertIndexInput());
            }
...
        }

but I always get application/octet-stream, anybody knows how to check if it is an csv or text MIME type ?

A: 

I'm guessing that would be answered in this post.

Can you verify that the machine used to upload the file is aware of the MIME type text/csv?

Also try verifying on file extension.

var fileExtension = System.IO.Path.GetExtension(file.FileName);
aanund