Dynamic path C#

Asked

Viewed 335 times

1

I am in search of a way to leave the path of a file inside my project in a dynamic way, currently this so:

string arquivoImagem = @"D:\Projetos\ProjetoSolution\Projeto.Web\Images\Gerenciador\login\logo.png";

I would not leave this fixed path as this above, as I do to leave it dynamic?

It is a web application, this path is of an image that will be inserted inside a report, it is an image of the application itself so there is no interference from the user, in case the report uses the path to insert the image in the report that later becomes a PDF. I wanted a way to solve this because we have problems when another developer opens the project the way does not exist, because the project may be in another location on his machine.

  • This on console or Windwos form ?

  • Define dynamic. What do you want to do? What you have described does not mean anything, we do not know how to help just with this.

  • You can put for the user to type the path

  • I made some editions explaining better

  • Solve what? Say what you need to do. The question there is to figure out what you need, not described in the question. Do you want to put it where? In a file? What type of file? A database? A global variable?

3 answers

6


2

In this case you want the physical path, which is a path at the system level ("D: Blabla...").

Do so (using HttpRuntime.AppDomainAppPath ):

string arquivoImagem = $@"{HttpRuntime.AppDomainAppPath}\Images\Gerenciador\login\logo.png";

1

Brayan, I had a similar problem. I created a configuration table, it contains an ID to distinguish the files and another the file path. Then just concatenate the strings:

-- dirParam is the information that is in the database.

string dirParam = "..imagens\..\..";
string arquivoImagem = dirParam + "\logo.png";

The case will go back 2 levels in the web page structure and then enter the images folder.

I hope it helped.

Browser other questions tagged

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