Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

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.

like image 710
Reahreic Avatar asked Aug 24 '12 20:08

Reahreic


People also ask

How to get full file path from FileUpload control in ASP net mvc?

Solution 1. filePath = FileUpload1. PostedFile. FileName; //gets only file name.

What is FileUpload control in asp net?

ASP. NET's FileUpload is an input controller used to upload files to a server. It appears on the screen with a browse button and opens up a dialogue box to choose a file or multiple files to upload from the local storage to the server. This is a server-side control provided by ASP.NET.


1 Answers

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);
like image 65
Josh Avatar answered Oct 17 '22 00:10

Josh