Is it possible to get full file name of uploaded file in asp.net mvc?
UPDATE The data contains only the file name, but doesn\'t the file path! See th
It depends on the browser.
Most browsers (FF, Chrome, Safari) do not send this information, primarily for security reasons. However, it appears as though some versions of IE do send the full client path.
This value will be stored in the FileName
property of the HttpPostedFile
.
The documentation for FileName should help. It says:
FileName: The name of the client's file, including the directory path.
In the following code, postedFile.FileName
will vary based on the browser. Therefore, it's important to always extract just the filename, and you might also get lucky and get the clientPath
too.
public ActionResult UploadFile(HttpPostedFile postedFile) {
var clientPath = IO.Path.GetDirectoryName(postedFile.FileName);
var filename = IO.Path.GetFileName(postedFile.FileName);
... Save the file, etc ...
}