0

I am coding in Metatrader and using ShellExecuteW to open a local browser with a html file that is written within Metatrader.

All works perfectly except when the directory that a user has his Metatrader platform installed in is a split name directory. ie: My FX and not MyFx.

If it is MyFx, there are no problems at all and the browser opens as intended showing the html file.

When the split name is used, it will try to open at eg: file:///G:/My and never see the rest of the address.

Relevant code as it stands is below. The user only puts in the name of the file eg: VisualizeV1 which is why there is the concatenation etc but that is not the issue.

 string newtpath =  TerminalPath() ;
// outputs G:\MyFX

string MT4_file_folder =newtpath+"/MQL4/Files/";
//  outputs G:\MyFX/MQL4/Files/

filesuffix=StringConcatenate("_",Symbol(),"_",TimeFrameStr,"_",fname_rpt_date);
// Outputs BrookyVisualize/VisualizeV1___EURUSD_H1__yr2014_mth6_dy19_hr23

fname=StringConcatenate(filename,filesuffix,".html");
// Outputs BrookyVisualize/VisualizeV1___EURUSD_H1__yr2014_mth6_dy19_hr23.html

file2find=StringConcatenate("file://",MT4_file_folder,visualize_folder,fname);
// Outputs G:\MyFX/MQL4/Files/BrookyVisualize/VisualizeV1___EURUSD_H1__yr2014_mth6_dy19_hr23.html

ShellExecuteW(0,NULL,Your_Internet_Browser,file2find,NULL,5);
// Opens firefox at address file:///G:/MyFX/MQL4/Files/BrookyVisualize/VisualizeV1___EURUSD_H1__yr2014_mth6_dy19_hr23.html

I have tried replacing the missing characters in the directory with &#160 and &nbsp. Also wildcard * and forward slashes.

If the replacements are inserted, the address is generated and opens in the browser as eg: file:///G:/My&nbsp&nbspFX/MQL4/ ...... which then gives a file not found error.

Could someone please advise what I should pass into ShellExecuteW re this path to resolve this issue.

Thank you.

Brooky
  • 11
  • 1
  • 1

1 Answers1

0

Sorted it out.

I have replaced the space with %20 and all is fine.

Code below that works for me now.

string tpath =  TerminalPath() ;
int replaced;
string newtpath="";
replaced = StringReplace(tpath," ","%20");
 newtpath = tpath;

MT4_file_folder =newtpath+"/MQL4/Files/";
Brooky
  • 11
  • 1
  • 1
  • The reason lies in the difference between URLEncoding and HTML Encoding. For example,   is HTML Encoding for while in URL encoding, it should be %20. You need to use the correct encoding (URL encoding). – jlee88my Feb 21 '16 at 14:43