I have an action that takes in a System.File
public bool UploadToServer( File file )
And I would like to use the file's original name in the server once it gets there. I have looked in MSDN's File Class but don't see anything that looks like I could get the filename or for that matter, the filepath. Is there an attribute I can use from the File
to get it's original name or should I simply make the signiture look like this:
public bool UploadToServer( File file, string fileName )
?
As @Marko suggested HttpPostedFile
is what I went with, I did not have Server.Web
in my resources for that project which was what was tripping me up.
1 Correct answerIn the Metadata panel there is a field below File Name called Original Filename. It¨s visible when Metadata is set to Exif and IPTC. In the Metadata panel there is a field below File Name called Original Filename.
The original filename of the asset resource from when it was created or imported.
Alternatively, head to the folder containing the files you want to delete, hit Shift + Right Click, and select Open a command window here. Then input "del [filename]" and press Enter.
Try the code below, this way you do not need to care about the path or any other security issues.
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
file.SaveAs(path);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With