This topic is locked
[SOLVED]

 getabspath problems open html file and read content

10/20/2020 9:40:23 AM
ASPRunner.NET General questions
A
admin author

Hi experts,
I am still newbie (after one year) in C#, using asprunner.net 10.4, i have problems reading content of a html (txt) file into a string in asprunner.net
The html file name is: au2mailer-2-emailtemplate10.html
this works (filename and path hardcoded)

string htmlstring = @"d:\web\localuser\domain.dk\public_html\crm\htmlfiles\au2mailer-2-emailtemplate10.html";

values["content"] = System.IO.File.ReadAllText(htmlstring);
this is needed but gives an error??

values["content"] = System.IO.File.ReadAllText(MVCFunctions.getabspath(values["filepath"]));
gives this error

Could not find file 'd:\web\localuser\domain.dk\public_html\crm\au2mailer-2-emailtemplate10.html'
why are the "htmlfiles" folder missing in the MVCFunctions.getabspath(values["filepath"]) ??
Thank you in advance
Michael from Denmark

admin 10/20/2020

What folder your ASPRunner.NET application resides in?
What is stored in the values["filepath"] variable?

A
admin author 10/20/2020



What folder your ASPRunner.NET application resides in?
What is stored in the values["filepath"] variable?


Hi Sergey,
ASPRunner.NET application resides in folder "CRM" on webserver.

values["filepath"] holds only name of the file, in this case au2mailer-2-emailtemplate10.html
Best regards and thank you
Michael

admin 10/21/2020

If ASPRunner.NET resides in "crm" folder and file name is stored as "au2mailer-2-emailtemplate10.html" there is no way for ASPRunner.NET to know that instead of "crm\au2mailer-2-emailtemplate10.html" you want "crm\htmlfiles\au2mailer-2-emailtemplate10.html".
You need to add "htmlfiles\" in front of values["filepath"] before passing it to getabspath() function.

A
admin author 10/21/2020



If ASPRunner.NET resides in "crm" folder and file name is stored as "au2mailer-2-emailtemplate10.html" there is no way for ASPRunner.NET to know that instead of "crm\au2mailer-2-emailtemplate10.html" you want "crm\htmlfiles\au2mailer-2-emailtemplate10.html".
You need to add "htmlfiles\" in front of values["filepath"] before passing it to getabspath() function.


Thank you Sergey,
I assume this is your suggestion?

string spath = "htmlfiles\" + values["filepath"];

values["content"] = System.IO.File.ReadAllText(MVCFunctions.getabspath(spath);
I have tryed before i posted, but using \ in the code gives an error at compiling!!
Best regards Michael

admin 10/21/2020

You didn't post the error message which you always should but I guess this article can help:

https://stackoverflow.com/questions/18532691/how-do-i-write-a-backslash-in-a-string

A
admin author 10/22/2020



You didn't post the error message which you always should but I guess this article can help:

https://stackoverflow.com/questions/18532691/how-do-i-write-a-backslash-in-a-string


Thank you Sergey, that did the trick
string bs = @"htmlfiles\";

values["content"] = System.IO.File.ReadAllText(MVCFunctions.getabspath(bs + values["filepath"].ToString()));
Best regards from Denmark (Michael)