Relative Path with virtual subdirectory

Asked

Viewed 647 times

1

Good afternoon,

I’ve been searching the internet for solutions to this my current problem with paths, but I can’t find.

Imagine that I have the following links:

www.site/Files/Uploads/image.png

www.sitedev/Client/Files/Uploads/image.png

In this case, in the first link I can always pick up the image path by back-end using HttpContext.Current.Server.MapPath, but when I try the same with the second link, it ignores the Client subfolder. In this case, I pass as parameter "~/Files/Uploads/image.png".

This subfolder exists in a development environment for hosting different applications.

Is there any method that can take both cases, or even with more subdirectories before where the application is?


Editing


One of the cases I’m having trouble with is the code to follow:

// Os valores das variáveis são:
//
// ultimoDigitoDoId = "4";
// Configuracoes.DiretorioUploadEmpresa = "~/Arquivos/uploads/empresas/"

var pasta = HttpContext.Current.Server.MapPath(String.Format("{0}{1}\\{2}",
    Configuracoes.DiretorioUploadEmpresa, 
    ultimoDigitoDoId, 
    "Imagens"));

if (!Directory.Exists(pasta))
    Directory.CreateDirectory(pasta)

When the folder is created and the files are saved in it, it is created outside the context 'Client', the one I showed above in the two link examples

  • Show how you’re using.

  • You have a Clientecontroller?

  • We need a sample of the code that performs the mapping. Server.MapPath is an option, but there are other.

  • @Andremesquita No, folder and images are saved with the code I entered in the edit

  • @Gypsy omorrisonmendez posted a sample

  • @Bigown I made an issue in my post. I believe that the main problem is the creation of the folder, because with the same folder created (in wrong place), it saves the images inside it using the same variable as reference.

  • @striterAlfa you have a controller called Clientecontroller? If there is, when you try to write the file in that folder, it is not being called an action named Files?

  • 1

    @Andremesquita looked up the name Clientecontroller in Solution and got no results. The problem, as I commented in the Gypsy reply below, is that "Client" is not a fixed directory, it varies according to the IIS in which the application is running. There are homologation environments that he calls "Homolog" and development that he calls "Dev". I can get this information from javascript using window.baseUrl, but I can’t get it from the backend

Show 3 more comments

1 answer

0


There is no problem with your code. It is just a question of the logic involved:

var pasta = HttpContext.Current.Server.MapPath(String.Format("{0}\\{1}{2}\\{3}",
    "Cliente",
    Configuracoes.DiretorioUploadEmpresa, 
    ultimoDigitoDoId, 
    "Imagens"));
  • The point, Gypsy, is that I could not put "Customer" fixed in the code. It is used for several different clients, and in certain test environments this name changes according to the folder in which the project is running on IIS. If it is inside a Homolog folder, for example, it would pick up a folder called Client again, it would fall into the problem of creating the folder and saving the information in the wrong place

  • 1

    This is solved with configuration and logic. Use <appConfig> to specify the client name, or environment, or convention you want to format the directory name. Other than that, it’s all right.

Browser other questions tagged

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