10 Replies Latest reply on Jan 22, 2014 9:32 AM by ch0c0halic

    Viewing Container Field Files (pdf, Word, Excel, pictures, etc)

    mc6994

      Conditions:

      1. I am using Filemaker Pro 13 on client machines and Filemaker Server 13 on a Mac server.

      2. The database tracks projects and each project can have multiple attachments that are stored in container fields. Hence 1 to many relationship between project table and attachment table.

      3. Attachement are viewed and accessed in a portal within the Project layout.

       

      Objective:

      I am trying to view pdf files or any document stored in the container easily when i am using either a mac or a PC. I didn't like the interactive content setup because i limited to the size of the container on the layout.

       

      Solution:

      I created a button to view the content with a script attached that export the file to the hard disk, save it as "Attachment Temp Save" and open it automatically. This approach works fine when i run the database locally on my machine. I named the file "Attachment Temp Save" to save a temporary copy on the hard drive that would be over written the next time i would open another attachment. This would save hard drive space in the long run.

       

       

      Problem:

      When the database is hosted on the server and i attempt to view the attachment using the same script. I see the following error message: "Attachment Temp Save" could not be created on this disk. Use a diffferent name, make more room on the disk, unlock it or use a different disk. (see attached sreen shot).

       

       

      Attached:

      Screen shot of the error message and pdf file with the script.

       

       

      Question:

      Please let me know if you see what's wrong with either the script or possibly server configuration settings that i may be missing. Also if there is a better approach to accomplish this, let me know.

      Thank you.

       

      Michel

        • 1. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
          Mike_Mitchell

          Michel -

           

          When you run a script on Server, it has access to only a couple of directories. Typically, you have to use directories that are within the path of the database itself (DocumentsPath or children thereof) or the Temporary directory. Therefore, it's good practice to use either Get ( DocumentsPath ) or Get ( TemporaryPath ) to establish the path for exporting files. This prevents permissions problems when the script is executed from Server.

           

          HTH

           

          MIke

          • 2. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
            ch0c0halic

            How are you defining the save path and file name?

             

            Here are some general guidelines just in case they can help.

            The path should use one of the FMP Get functions for a default location, for example Documents or temp. This localizes it to he specific computer.

            Include the appropriate system prefix, filemac: or filewin:.

            “filemac:/Path/filename" should be a calculation assigning the value to a Variable. Use the Variable in the Save file to disk.

            NOTE: The save file script step location definition is not a calculation so don’t try putting this in that dialog.

            File name would be fixed but be sure to include the extension.

            • 3. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
              mc6994

              Thank you Mike Mitchell and Ch0C0halic, defining the file path for the client machine (mac or PC) using the Get (DocumentsPath) function seems to do the trick.

               

              I noticed though that the mac is more tolerant. If i save a file without the extension in the filename, the mac can still open it automatically with the right application (adobe, Word, excel, etc). But on a PC the file (in my case named "Attachment Temp Save") needs to be given an extension (.doc, .xlsx, .jpg, .pdf, etc). I couldn't find a function that can get the extention of the file stored in the container. The closest function in FM Pro 13 is GetContainerAttribute which can extract the file name.

               

              Does this mean that i need to parse the character string in the filename to find extension?

               

              Most extensions are four characters (including the dot). But the .xlsx throws a monkey wrench. Are there built in functions in FM that would extract the filename extension?

               

              The reason i want to use the same filename is to keep overwriting it each time I view a container field payload. I wouldn't want to keep storing additional files on the drive as would be the case if i used the original filename.

               

              Regards,

               

              Michel

              • 4. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
                robwoof

                One way to use the original filename without clogging up the HD is to use the Temp location (cleared every reboot). You get a path to it using Get ( TemporaryPath ). If you select the "Automatically Open File" box, the user neither knows nor cares where the file has been saved to - it just opens.

                 

                HTH

                Rob

                 

                (edited to fix typos)

                • 5. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
                  mc6994

                  Thank you Rob. I'll give it a try.

                   

                  Update:

                   

                  Thank you all on this thread. I got it to work.

                  Here is the script for anyone that may need to do the same thing. If you see any red flag in this script, please let me know. I am fairly new at this (just a little over a month).

                   

                   

                  #Export attachment to hard drive and open file automatically

                  If [ not IsEmpty(Project_Attachments::Project Attachement File) ]

                  Set Variable [ $MacTempFilePath; Value:Get(TemporaryPath) & GetContainerAttribute ( Project_Attachments::Project Attachement File ; "filename" ) ]

                  Set Variable [ $WinTempFilePath; Value:"filewin:" & Get(TemporaryPath) & GetContainerAttribute ( Project_Attachments::Project Attachement File ; "filename" ) ]

                  Set Variable [ $TempFilePath; Value:Choose(Abs(Get(SystemPlatform))-1; $MacTempFilePath; $WinTempFilePath) ]

                  Export Field Contents [ Project_Attachments::Project Attachement File; “$TempFilePath”; Automatically open ]

                  Else

                  Show Custom Dialog [ Title: "No Attachment Stored in Field"; Message: "Please make sure to include an attachment file in the

                  Project Attachment field prior to clicking the View button"; Default Button: “OK”, Commit: “Yes” ]

                  End If

                  • 6. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
                    Mike_Mitchell

                    Michel -

                     

                    No, there’s no function to extract the filename extension automatically. You’ll need to use text parsing functions to do that. You start with GetAsText ( {container field} ). The results of that function will vary based on the type of file and whether it’s stored internally or externally, so you’ll have to put some conditional statements into your calculation based on your particular situation.

                     

                    Once you have the filename, use the Position function to extract the position of the last “.” character in the string. This will give you the point at which the filename extension starts. You can then use the Right function to extract the extension itself.

                     

                    (I leave the details as an exercise for the reader.)     

                     

                    Mike

                    • 7. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
                      erolst

                      Mike_Mitchell wrote:

                      Once you have the filename, use the Position function to extract the position of the last “.” character in the string. This will give you the point at which the filename extension starts. You can then use the Right function to extract the extension itself.

                      (I leave the details as an exercise for the reader.)     

                      Mike

                       

                      Great of you, Mike …

                       

                      I think briefer than using Right() (or Middle()) is

                       

                      Let ( [

                      s = Substitute ( yourFilename ; "." ; ¶ )

                      ] ;

                      GetValue ( s ; ValueCount ( s ) )

                      )

                       

                      On that topic: I wish FMI would extend/modernize the palette of built-in functions.

                       

                      This is how you can parse an extension in Ruby:

                      yourFilename.split(".").last

                       

                      Same logic as with GetValue(), but much more convenient …

                      • 8. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
                        user21485

                        Hi,

                        I may have missed the point here but why not create a layout that only contains an interactive content field locked on all 4 sides, and have this displayed as a popup window modal fashion. Resizing the window would change the size of the content. Have your portal button open this window with the content. It would save the overhead of copying files and cleaning up afterwards This window could also contain a print button for your clients to printout these PDFs

                         

                        Que

                        • 9. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
                          Mike_Mitchell

                          Because the interactive content field doesn't display all possible content. The OP included Word, Excel, etc., and interactive content fields don't display those file types.

                          • 10. Re: Viewing Container Field Files (pdf, Word, Excel, pictures, etc)
                            ch0c0halic

                            The easy way is to substitute a space for the periods. That makes it a word break. Then use Rightwards (filename_spaces ; 1 ) to extract the extension.

                             

                            Set a variable with this value and use it for both the file name extension and to switch layouts.

                             

                            $file_ext =

                            Rightwords ( Substitute ( filename ; “.” ; “ “ ) ; 1 )

                             

                             

                            Create two layouts, or use tabs, one for interactive container and one without. Use the file extension to switch which one is used/showing/or export.

                             

                            If ( PatternCount ( “xls, pdf” ; $file_ext ) > 0

                              switch to interactive container tab or layout

                            else if ( PatternCount ( “txt, rtf” ; $file_ext ) > 0

                              switch to non-inteactive container tab or layout

                            else

                              export filed content to $temp_location

                            end if