Last Updated: February 25, 2016
·
3.737K
· iondrimba

Problems with posted filename on IE

When working with posted files make sure to use Path.GetFileName for extrancting the posted file name.

HttpPostedFileBase postedFile = httpContext.Request.Files[0];
string postedFileName = postedFile.FileName;

/* FF CHROME WORKS FINE */
OUTPUTS : someFile.jpg

/* IE OUTPUTS C:\user\folder\folder\someFile.jpg

Correct way:

HttpPostedFileBase postedFile = httpContext.Request.Files[0];
string postedFileName = Path.GetFileName(postedFile.FileName);