Get folder of solution C #

2

I have a solution with 4 projects inside. In my controller I need to open an HTML that is inside another project, but I can not open the file folder.

Below is the following with my structure:

TheclassfileistheUtils.cscontrolleriswithin1-Services/JWT/ControllersItriedtoopenthefileusingthefollowingcode...

CrieiumaclassenoprojetoondeestámeuarquivoHTML.publicstaticclassUtilDirectory{publicstaticstringGetDirectory(){returnDirectory.GetCurrentDirectory();}}

InthecontrollerwhereImaketheaccessclassinstanceasfollows:

vardirectory=UtilDirectory.GetDirectory();StreamReaderreader=newStreamReader(directory+@"/ApiUtils/HtmlEmail/CorpoEmailBoletoDimensao.html");

string mensagem = reader.ReadToEnd();
reader.Close();

But when I do this by doing this I end up getting the folder of my project that is the controller and not the Html itself.

Can you help me out?

    
asked by anonymous 28.05.2018 / 14:46

2 answers

0

I solved the problem by adding a data folder to the solution.

string baseDir = env.ContentRootPath;
AppDomain.CurrentDomain.SetData("DataDirectory", System.IO.Path.Combine(baseDir, "App_Data"));

And retrieving the folder in my controller for access to the file as follows.

      string dataDir = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();

      StreamReader reader = new StreamReader(dataDir + @"/CorpoEmailBoletoDimensao.html");
    
30.05.2018 / 13:09
1

Too complicated to keep it that way. Add the class library ApiUtils file as a reference in the Web project. This way you can use it as follows:

  

StreamReader reader = new StreamReader (directory +   @ "/ BodyEmailBoletoDimension.html")

See steps 1, 2, and 3 on the link: link

    
29.05.2018 / 23:16