How to write to Common Data Patch correctly?

 

i cannot seem to get it right. I write without problems to allowed //files folder, but i cannot create any file in common data folder. Code goes like this:

int OnInit(void)
{

            string outString = "test1";
            ResetLastError();
            string common_data_path=TerminalInfoString(TERMINAL_COMMONDATA_PATH);
            string filename="";
            StringConcatenate(filename, common_data_path,"\\Files\\testfile");
            Alert("cdp=", filename);  		//debug
            int filehandle=FileOpen(filename,FILE_WRITE|FILE_BIN);
            if(filehandle!=INVALID_HANDLE)
            {
               FileWriteString(filehandle, outString);
               FileClose(filehandle);
            } else Alert("Error - problem saving file: ",GetLastError());
            
            return(INIT_SUCCEEDED);
}

 i get ERROR 5002 (too long file name) error all the time both in MT5 and MT4. How do I do it right?

 
Grzegorz Korycki:

i cannot seem to get it right. I write without problems to allowed //files folder, but i cannot create any file in common data folder. Code goes like this:

 i get ERROR 5002 (too long file name) error all the time both in MT5 and MT4. How do I do it right?

You don't need to add the path to the file name.

int filehandle=FileOpen(filename,FILE_WRITE|FILE_BIN|FILE_COMMON);
 
Alain Verleyen:

You don't need to add the path to the file name.

Thank You! I was getting frustrated.