3

I'd like to ask if its possible for 4D to create a document on a network directory. For example:

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
B.Bippus
  • 5
  • 2
Jun Dolor
  • 609
  • 2
  • 11
  • 25

3 Answers3

0

one way to do this is:

you can map your second machine's drive to machine where your 4d database is running. then this drive would behave like a local drive.

for example: i have mapped a drive which is named as "D" drive on remote machine, and it becomes "W" drive on machine where 4D database is running. then you can use this code

c_Text(vPath)

vPath:="W:\var\www....." //temp path.....

vDoc:=Create document(vPath+"notes.txt")

If(OK=1)

SEND PACKET(vDoc;"Hello World")

CLOSE DOCUMENT(vDoc)

End if

0

I know this is an old question, but there aren't too many of us 4D coders floating around here, so I'll answer this for posterity!

Yes, you can create a document on a network share like this, assuming you have the appropriate permissions to do so.

In this case, I think you just need to be careful of how you escape the path. Ensure that you're doubling up your backslashes so that the code block looks like this (note the extra backslashes around the IP address and folder name):

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 

Hope this helps!

0

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 
Tim Penner
  • 3,551
  • 21
  • 36