Yes, although undocumented, the CREATE DOCUMENT
command does works with a valid UNC path provided that you have sufficient privileges to create a document at the path given.
However, you have an issue with your sample code. Your issue comes down to your usage of the backslash \
character.
The backslash \
character is used for escape sequences in 4D and is therefore used for escaping many other characters, so it must also be escaped itself. Simply doubling all of your backslashes in your sample code from \
to \\
should correct the issue.
Your sample code:
vIP:="\\100.100.100.100" // this is a hypothetical IP
vPath:=vIP+"\storage\"
vDoc:=Create document(vPath+"notes.txt")
If(OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
Should be written like this:
vIP:="\\\\100.100.100.100" // this is a hypothetical IP
vPath:=vIP+"\\storage\\"
vDoc:=Create document(vPath+"notes.txt")
If(OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
Your code could be further improved by using Test Path Name
to confirm the path is valid, and that the file does not exist. Then if it does exist you could even use Open Document
and Set Document Position
to append to the document, like this:
vIP:="\\\\100.100.100.100"
vPath:=vIP+"\\storage\\"
vDocPath:=vPath+"notes.txt"
If (Test path name(vPath)=Is a folder)
// is a valid path
If (Not(Test path name(vDocPath)=Is a document))
// document does not exist
vDoc:=Create document(vDocPath)
If (OK=1)
SEND PACKET(vDoc;"Hello World")
CLOSE DOCUMENT(vDoc)
End if
Else
// file already exists at location!
vDoc:=Open document(vDocPath)
If (OK=1)
SET DOCUMENT POSITION(vDoc;0;2) // position 0 bytes from EOF
SEND PACKET(vDoc;"\rHello Again World") // new line prior to Hello
CLOSE DOCUMENT(vDoc)
End if
End if
Else
// path is not valid!
ALERT(vPath+" is invalid")
End if