FileUploads and rooted directories
-
03-07-2019 - |
Question
The FileUpload control requires me to provide a rooted directory in the SaveAs() method. However, I would much rather the uploaded files go into a virtual directory, such as "~/UserFiles/[username]/[filename]". Is there a way for me to accomplish that?
Solution
Use the pages MapPath method:-
ctl.SaveAs(MapPath("~/UserFiles/[username]/[filename]"));
OTHER TIPS
No, the keyword is requires. You can use your script to copy the file after the download.
Sometimes the MapPath is not directly accessible.
In this case use
ctl.SaveAs(Server.MapPath("~/UserFiles/[username]/[filename]"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow