Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

Commented Issue: HttpPostedFileBaseModelBinder and browsers that send full file path [835]

$
0
0
Certain browsers (IE) send the full file path of a file from an <input type="file"/>.

It seems this behaviour was turned off in IE8 onwards (but still remains as an option to turn back on through IE optons).

Seeing as a HttpPostedFileBase has the property "FileName" should the model binder not try its best to populate this with the actual file name?

I'm suggesting perhaps changing the HttpPostedFileBaseModelBinder to at some point do a Path.GetFileName(theFile.FileName) in order to workaround this behavour and not be so misleading as to what the FileName property will have.
Comments: In most cases it works fine. However in some versions of IE when model binding to a file the bound parameters FileName would be something like C:\myfile.jpg instead of just myfile.jpg (which chrome and firefox send). Now if you're assumimg that you always get back myfile.jpg (which the FileName property on the HttpPostedFileBase suggests) you can run into some issues. Of course these issues can be fixed if you just do a Path.GetFileName("c:\myfile.jpg") and it would return myfile.jpg its just that the property name is misleading as it isnt always the filename its sometimes the full path.

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>