0
I am uploading an image I receive via form using C# ASP.NET. My code is working like this:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file)
{
try
{
if (file.ContentLength > 0)
{
string _FileName = Path.GetFileName(file.FileName);
string _path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName);
file.SaveAs(_path);
}
ViewBag.Message = "File Uploaded Successfully!!";
return View();
}
catch(Exception e)
{
ViewBag.Message = "File upload failed!!";
return View(e.Message);
}
}
But the directory he is saving is virtual (folder created within the project). I can save this image in a physical directory (folder that is in another location other than within the project)?
Pass the physical location to your _path string = "c: temp uploads " + filename ;
– Evandro
Only if you have permission
– novic
Really gives permission error. Can I get through this lock?
– Diego Grossi
The physical directory is your machine or is an external server of some company?
– Leonardo Bonetti
Company server, but on the same machine that is running the application, but in folder that does not belong to the project, type c: imgTemporarias
– Diego Grossi
Is the Server running the application IIS? If you are trying to give permission in the local folder to the IIS_IUSRS user.
– Evandro
The folder already has permission for the IIS_IUSRS user, but now it is giving the error The Saveas method is configured to require a root path, and the path 'wayDoServidor nameDaImage' has no root.
– Diego Grossi
already tried to pass the path (@"C: imgTemporarias" +Fileupload1.Filename)
– Evandro
It gives the same error. I am in the development environment, running the application on my machine and sending to the server that is another machine. Could that be the problem?
– Diego Grossi
The error is not the environment no, I tried in the production environment and gives error also.
– Diego Grossi