FileUpload.PostedFile.Filename includes all the client Path info, but only in IE

This is a known problem documented on the MSDN – I’m sure I’ve been caught by this before so thought i would blog it!

Firefox and IE7.05XX treat the PostedFile.Filename property differently.

In Firefox, calling FileUpload.PostedFile.Filename will return the name of the file, with no path information.

In IE7, calling FileUpload.PostedFile.Filename will return the full path of the file + the filename.

e.g. if the client file is located at c:\My Documents\Test.xls, Firefox will return ‘Test.xls’, and IE7 will return ‘c:\My Documents\Test.xls’

  1. #1 by Bhalchandra on September 6, 2010 - 13:01

    Thnx buddy. I was struggling with this. Is theres any solution to this problem

  2. #2 by shawson on September 13, 2010 - 10:19

    There’s no proper fix, but you can work around it by just checking for slashes in the path that comes back, and clean it up if there is- I do this;

    HttpPostedFile f = control.PostedFile;
    var cleaned_filename = f.FileName.ToLower();
    // ie leaves the path data on the front, so get rid of that!
    if (cleaned_filename.Contains(“\\”))
    cleaned_filename = cleaned_filename.Substring(cleaned_filename.LastIndexOf(“\\”), cleaned_filename.Length + 1 – cleaned_filename.LastIndexOf(“\\”));

  3. #3 by kyaw on May 21, 2012 - 04:51

    Pls just use FileUpload.Filename
    it’s ok for me

  4. #4 by Kyle on June 21, 2012 - 21:08

    Thanks shawson, your solution worked great for me.

  5. #5 by lokesh on November 5, 2012 - 09:36

    kyaw :
    Pls just use FileUpload.Filename
    it’s ok for me

    kyaw :
    Pls just use FileUpload.Filename
    it’s ok for me

    thanks kyaw it’s is also useful tome

(will not be published)

I absolutely love these. They came at the lace wigs are good quality, and very soft. Absolutely love these extensions. I just love this hair. Hair came on time, I waited until after hair extensions uk very full, no shedding and it is been installed for 3 weeks now and yes I jus ordered 3 more bundles. Lol. I definitely recommend this company for your bundles ladies. They are soft, hair bundles on the head for human hair wigs and I would continue to recommend them. I have thinner hair so they cover and blend nicely.