HttpPostedFile.FileName - Different from IE

后端 未结 4 1361
南旧
南旧 2020-12-09 02:44

When I upload a file to a site using the ASP:File control the FileName property is different in IE and Firefox. In Firefox, it just provides the name of the file, but IE pr

相关标签:
4条回答
  • 2020-12-09 03:17

    You also can use Path.GetFileName(File.FileName) that return only file name. Example:

    Dim File As HttpPostedFile = context.Request.Files("txtFile")
    ' let's FileName is "d:\temp\1.txt"
    Dim FileName As String = Path.GetFileName(File.FileName)
    ' FileName will be "1.txt"
    
    0 讨论(0)
  • 2020-12-09 03:22

    This is a security/privacy concern, firefox/mozilla is doing it right and you will not get a way to get the full path without an add-in, applet, silverlight, flash or some other mechanism.

    Here is more info on Mozilla's stance:

    https://developer.mozilla.org/en/Updating_web_applications_for_Firefox_3

    See the section on Security Changes->File upload fields

    I hope IE will follow suit so we have a consistent and secure environment.

    0 讨论(0)
  • 2020-12-09 03:31

    In IE8, this behavior has changed and it will ONLY pass the file name, not the full path. ;-)

    Details and link to the IE Blog post discussing the change in IE8: http://blogs.msdn.com/b/webtopics/archive/2009/07/27/uploading-a-file-using-fileupload-control-fails-in-ie8.aspx

    Serverside apps looking to parse out the filename should check for, but not expect there to be backslashes in the filename.

    IE8 user setting override: http://blogs.msdn.com/blogfiles/webtopics/WindowsLiveWriter/UploadingafileusingFileUploadcontrolfail_167/clip_image002_2.jpg

    0 讨论(0)
  • 2020-12-09 03:33

    A simple workaround for this tested in IE and Chrome

    new FileInfo(myHttpPostedFileBase.FileName).Name
    

    This will ensure you always get just the file name even if the path is included.

    0 讨论(0)
提交回复
热议问题