The project is an MVC 4 C# based web application.
I'm currently working locally and would like to have the ability to upload a file to my locally running application in debug mode and have the file saved to the web server instead of the my local folder.
Currently we are using:
if (!System.IO.File.Exists(Server.MapPath(PicturePath)))
{
file.SaveAs(Server.MapPath(PicturePath));
}
How can we leverage this code to save to a webserver directly. Is that even possible?
Right now the file gets saved to my local path and the path is stored in the database, we then have to upload the files to the webserver manually.
The
SaveAs
function takes a filename and will save the file to any path you give it, providing the following conditions are met:I would suggest you have a web.config setting that can be checked when running your code. Then you can decide if to use
Server.MapPath
or an absolute path instead.For example, in "debug" more (running locally) you might have the following settings:
and in "live" mode:
Then your code may look something like this: