KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Programmatically set a relative Default HTML Root
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: June 29, 2011

The SET HTML ROOT command modifies the root folder of the 4D web server. The command accepts an absolute path for the folder, but with some additional code, the command can be used to set a path that is relative to the 4D database.

The following code accepts 2 parameters: a name for the webfolder and a number for how many levels above the structure file the folder is:

C_TEXT($1;$name_t)
C_LONGINT($2;$levelUp_l)

C_TEXT($path4D_t;$pathWeb_t;$char_t)
C_LONGINT($i;$length_l;$found_l)

$name_t:=$1
$levelUp_l:=$2

//get path to the structure file
$path4D_t:=Get 4D folder(Database Folder)
$length_l:=Length($path4D_t)

$found_l:=0
$pathWeb_t:=""

//the 4D Path ends with a folder separator, so our search needs to increase by 1
$levelUp_l:=$levelUp_l+1

//iterate through each character of the path
For ($i;$length_l;1;-1)
 $char_t:=$path4D_t$i

   //check for the folder separator character
  If ($char_t=Folder separator)
   $found_l:=$found_l+1

   If ($found_l=$levelUp_l)
     //we are at the correct position that we want

     //now build the new path
    $pathWeb_t:=Substring($path4D_t;1;$length_l-($length_l-$i))
    $pathWeb_t:=$pathWeb_t+$name_t+Folder separator

    $i:=1 //stop the loop

  End if
 End if
End for

//use the new path as the root folder
SET HTML ROOT($pathWeb_t)


As an example, here is a call that sets the HTML root folder to the folder named "mySiteFolder", which is located 1 level above the structure file:

SetHTMLPath ("mySiteFolder";1)

STOP WEB SERVER
START WEB SERVER


Note the last two lines are included because the web server needs to be restarted in order for the SET HTML ROOT command to take affect.