Create a document online using a 4D database

I would like to ask if it is possible for 4D to create a document in 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

      

+3


source to share


3 answers


one way to do it:

you can map your second machine drive to the machine your 4d database is running on. then this disk will behave like a local disk.

eg: I mapped a drive called "D" on the remote computer and it becomes "W" on the machine where the 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 PACKAGE (vDoc; "Hello World")

CLOSE DOCUMENT (vDoc)

End if

0


source


I know this is an old question, but there aren't that many 4D coders here, so I'll answer posterity!

Yes, you can create a document on a network share, for example, if you have the appropriate permissions to do so.

In this case, I think you just need to be careful how you avoid the path. Make sure you double the backslash so that the block of code 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


source


Yes, although the undocumented command works with a valid UNC path , provided you have sufficient privileges to create the document at the specified path. CREATE DOCUMENT

However, you have a problem with your example code. Your problem boils down to using the backslash character \

.

The backslash character is \

used for escape sequences in 4D and is therefore used to escape many other characters, so it must also be escaped by itself. Just doubling all your backslashes in your example code from \

to \\

should fix this problem.

Your example 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

      

It 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 can be further improved with Test Path Name

to confirm that the path is valid and that the file does not exist. Then, if it exists, you can even use Open Document

it Set Document Position

to append to the document, for example:

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 

      

0


source







All Articles