Assuming a Action of Controller, you can get the file as follows:
private const String DiretorioCurriculos = "~/Curriculos/";
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> EnviarCurriculo([Bind(Include = "CurriculoCandidatoId,NomeCandidato,Email,TelefoneContato,TelefoneCelular,ArquivoCurriculo,SetorPreterido,Comentarios")] CurriculoCandidato curriculoCandidato)
{
if (curriculoCandidato.Arquivo != null && curriculoCandidato.Arquivo.ContentLength > 0)
{
string nomeArquivo = Regex.Replace(curriculoCandidato.NomeCandidato + "-" + Path.GetFileName(curriculoCandidato.Arquivo.FileName), @"\s+", "");
string caminho = Path.Combine(Server.MapPath(DiretorioCurriculos), nomeArquivo);
curriculoCandidato.Arquivo.SaveAs(caminho);
curriculoCandidato.CaminhoArquivoCurriculo = nomeArquivo;
}
...
Arquivo
is the type HttpPostedFileBase
.
You can also manipulate bytes directly through the property InputStream
.
The file doesn’t exactly have one path
. The file is usually in the body of the request, through a sequence of bytes.
Thanks to the @Gypsy reply, however, I really need the file path... by my model I can already access the file Inputstream and manipulate what I need it, but for another logic I really need the physical location where the file came from at the time of Submit.
– AbnoanMuniz
You, the customer machine site?
– Leonel Sanches da Silva
in case, the file will always come from a server, however it may come from separate folders.
– AbnoanMuniz
HttpPostedFileBase
does not save information from the file’s source directory. I think you will have to rethink its logic.– Leonel Sanches da Silva