Using another path to pull files from a folder outside Directoryinfo

Asked

Viewed 91 times

0

My project is running perfectly, but I’d like to replace that path DirectoryInfo to another who pulls himself straight from the folder without using my directory.

Code:

public List<Arquivos> GetArquivos()
{

    List<Arquivos> lstArquivos = new List<Arquivos>();
    //DirectoryInfo dirInfo = new DirectoryInfo(HostingEnvironment.MapPath("~/Arquivos"));
    DirectoryInfo dirInfo = new DirectoryInfo("C:/Users/Usuario/source/repos/FEESC/FEESC/UploadedFiles");
    int i = 0;
    foreach (var item in dirInfo.GetFiles())
    {
        lstArquivos.Add(new Arquivos()
        {
            arquivoID = i + 1,
            arquivoNome = item.Name,
            arquivoCaminho = dirInfo.FullName + @"\" + item.Name
        });
        i = i + 1;
    }
    return lstArquivos;
}
  • "pull directly from folder" q folder ? this is web or winforms ?

  • It’s ASP.NET MVC but I don’t want to have to use the whole directory wanted to make a ~/Uploadfile

1 answer

0


try like this:

System.Web.HttpContext.Current.Server.MapPath("~/Arquivos/");

DirectoryInfo dirInfo = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath("~/Arquivos/"));
  • yes exactly that, thank you very much

Browser other questions tagged

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