0

I need to save the files somewhere else because the server that this application is getting full

How would I change the virtual path to a physical path?

This is my original controller

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(FormularioDoUploadViewModel formularioDoUploadViewModel)
        {
            if (ModelState.IsValid)
            {
                List<DetalhesDoArquivoViewModel> detalhesDosArquivos = new List<DetalhesDoArquivoViewModel>();

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        DetalhesDoArquivoViewModel detalhesDoArquivo = new DetalhesDoArquivoViewModel()
                        {
                            FileName = fileName,
                            Extension = Path.GetExtension(fileName)
                        };

                        detalhesDosArquivos.Add(detalhesDoArquivo);
                        var path = Path.Combine(Server.MapPath(@"~/App_Data/Upload/"), detalhesDoArquivo.Id + detalhesDoArquivo.Extension);
                        file.SaveAs(path);
                    }

                }

                formularioDoUploadViewModel.DetalhesDoArquivo = detalhesDosArquivos;

                _uploadServices.AdicionarArquivo(formularioDoUploadViewModel);

                return RedirectToAction("Index");
            }

            return View(formularioDoUploadViewModel);
        }

and I want to insert this path into the variable path:

 var path = Path.Combine(Server.MapPath(@"C:\Users\bwm6\Desktop\uploads"), detalhesDoArquivo.Id + detalhesDoArquivo.Extension);
mxmissile
  • 11,464
  • 3
  • 53
  • 79
AllMuch
  • 29
  • 7

1 Answers1

0

Replace the relative path with your absolute path. Be sure your permissions are in order to write to the directory. You will can use System.IO.File to access the systems files. This link my help you understand how to do so: How to convert a relative path to an absolute path in a Windows application?

Menefee
  • 1,475
  • 1
  • 17
  • 26