d1g2uq
Last Updated: February 25, 2016
·
2.151K
· iondrimba
178548

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);
Say Thanks
Respond