Save File in Physical Path

Asked

Viewed 1,257 times

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 ;

  • Only if you have permission

  • Really gives permission error. Can I get through this lock?

  • The physical directory is your machine or is an external server of some company?

  • 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

  • Is the Server running the application IIS? If you are trying to give permission in the local folder to the IIS_IUSRS user.

  • 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.

  • already tried to pass the path (@"C: imgTemporarias" +Fileupload1.Filename)

  • 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?

  • The error is not the environment no, I tried in the production environment and gives error also.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.