Jump to content

Reading text contents from a Container Field?

Recommended Posts


Mac and WIndows are indeed different. Now, I have the same question again like before (see below) — only this time for Windows.

"Comment" suggested correctly to use the TextDecode function, that did the trick — on Mac. However, this does not work on Windows. I have the following situation:

A windows text file in a container field g::tmpc, on a windows PC using FM 18 with the following contents:

Size         : 64317550592
Size         :
Size         : 1099508477952
Size         : 23024804278272

When I copy the contents of the container field g::tmpc into a text field g::tmpt with

Base64Decode ( Base64Encode ( g::tmpc ) )

Everything is as expected on a Mac.

However, on Windows, something weird happens:  The Length of the field is correct (+ 2 chars), so the content is definitely there. In the Data Viewer the contents is shown only as "◊◊S”, "S" being the first "S" of the first line. But nothing more is shown. When I try to get to the content, for example with

Middle ( g::tmpt ; 3 ; 100 )

I only receive "S", not even the spaces after it.

When I look at the Layout in browse mode, I can see its contents, albeit completely distorted, like this:

◊◊S  i  z  e                      :   6  4  3   1  7  5  5  0   ...

And between every line is an empty line inserted, and whoever knows what else.

So, my question:  Any ideas? Has anyone ever tried to read text from a container field on Windows?

Thanks a lot for any help!



P.S.: Even though "Comment" suggested to use the TextDecode function, I prefer to use the Base64-Encode-Decode variation. That also works with binary contents. And, the Base64-Encode-Decode trick enables me to rename a file inside a container field.

P.P.S.: I did find a bad trick that I used, because I only need the number in the first line of the text. To my surprise, the following worked to just retrieve the number that I needed:  64317550592

GetAsNumber ( GetValue ( g::tmpt ; 1) )





Link to post
Share on other sites

Hard to analyze the situation without seeing the text file in the container. When you use the TextDecode() function, you get to choose the character encoding to be used in the process. This needs to be the same encoding as the one that was used to encode the original text file. From what you describe, I would guess (!) you are looking at an UTF-16 encoded file that was decoded as UTF-8.

Also, as everyone knows (or at least should know), a line break in Windows is marked by a combination of the CR and LF characters. Other systems can easily interpret this as a double line break.


Link to post
Share on other sites

Hi, and thanks again.

I have already tried every possible encoding. Please see attached picture.

And even though GetAsNumber ( GetValue ( g::tmpc ; 1 ) ) works, ( GetValue ( g::tmpc ; 3 ) ) does not work. Really strange.


Screen Output.png

Link to post
Share on other sites
Posted (edited)
  • And here are the text files:

1) The original windows text file with four lines

2) The contents of this file converted with base64-encode-decode (the exact contents of what you can see in the layout in g::tmpc, generated with «Export Field Contents»)


original windows text file.txt tmpc container base64-enc-dec.txt

Edited by gczychi
Link to post
Share on other sites

OK, I have found another not so elegant way:   ExecuteSQL

Let ( [ ~fmsql_execute = True ;
	~query = "

	SELECT tmpc3 FROM g

	" ;
	~columnSeparator = Tab ; ~rowSeparator = ¶ ;
	~result = If ( not ~fmsql_execute ; ~query ; ExecuteSQL ( ~query ; ~columnSeparator ; ~rowSeparator ;
	"") ) ;

	~t = Right ( ~result ; Length ( ~result ) - 6 ) ;

	~~ = "" ] ;
	~result  & ¶ & ¶ & ~t	
) // end let

Produces this output:

������Size         : 64317550592

Size         : 

Size         : 1099508477952

Size         : 23024804278272

Size         : 64317550592

Size         : 

Size         : 1099508477952

Size         : 23024804278272


Apparently, it is next to impossible to get to the actual binary data that is stored in FileMaker.

I wonder if there is a more elegant solution.



Link to post
Share on other sites

I downloaded your text file and opened it in a text editor. As I suspected, this is a UTF-16 encoded file, with CRLF line endings. Filemaker's TextDecode)() function does not support UTF-16 encoding (which is rather surprising, since that is FMP's internal text format and the default when exporting a text field). I don't know of a way to make this work within Filemaker. Might be possible by using Javascript in a web viewer. 

Edited by comment
Link to post
Share on other sites

That’s very interesting! The text file is the output of a PowerShell command and apparently it is saved by default as UTF-16.

I haven’t checked it out yet, but there seems to be a PowerShell command that can convert the file into UTF-8:

Set-Content -Encoding UTF8


Thanks a lot!


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.