Reahreic Reahreic - 1 month ago 5
ASP.NET (C#) Question

asp.net FileUpload.FileName returns full path in ie when not needed

From what i understand for asp.net FileUpload.FileName ruturns the full path while in firefox it returns just the filename. How would i remove the path from the returned string as i just need the html encoded filename.

Answer

You can use the Path static class to get the filename.

var fileName = Path.GetFileName(somePath);

And the HttpUtility static class to encode it.

var encoded = HttpUtility.HtmlEncode(fileName);
Comments