BSBO_SaveDocumentDesktop
Back to ListDescription: Copy a file from the document store to the users desktop or a save location.
FileMaker Prototype:
Set Variable [$res; ACFU_BSBO_SaveDocumentDesktop( string_DocStore; string_ArchiveSubPath; string_Title)]
Category: BOOTSTRAP
NOTE: The bootstrap library comes preloaded in the plugin. Read more
Function source:
/*
Copy a document from a document store to users desktop.
DocStore: the start path for the archive
ArchiveSubPath: The relative path starting from DocStore (including the filename). Designed to be a
common subpath to be used from both mac and windows, using :, / or \ as direcotory seps.
Title: An optional title of the document to be used as target filename (+ extention of the original file )
Example (Win):
ACFU_BSBO_SaveDocumentDesktop ( "\\192.168.1.20\vArchive\myDocArchive"; "Customers/11213/Contract.docx"; "Customer 11213 Contract" )
or (mac)
ACFU_BSBO_SaveDocumentDesktop ( "vArchive:myDocArchive"; "Customers/11213/Contract.docx"; "Customer 11213 Contract" )
If the user hold the Alt key down while doing this, a File Save dialogue appears for user to select alternate name or location.
Else, it will be copied to the users desktop.
*/
function BSBO_SaveDocumentDesktop (string DocStore, string ArchiveSubPath, string Title)
functionID 231;
if ( DocStore == "" ) then
throw "DocStore for document not set";
end if
if ( ArchiveSubPath == "" ) then
throw "ArchiveSubPath for document not set";
end if
if ( isMac ) then
DocStore = "/Volumes/" + substitute ( DocStore, ":", "/");
else
DocStore = substitute ( DocStore, "\\", "/");
end if
if ( ! directory_exists ( DocStore ) ) then
throw "Doc Store volume not available: " + DocStore;
end if
if ( right(DocStore, 1) != "/") then
DocStore += "/";
end if
ArchiveSubPath = substitute ( ArchiveSubPath, ":", "/");
ArchiveSubPath = substitute ( ArchiveSubPath, "\\", "/");
string SourceFile = DocStore + ArchiveSubPath;
string defname;
if ( Title == "" ) then
defname = regex_replace("^(.+)/(.+\..+)$", SourceFile, "\2");
else
Title = substitute ( Title, ":", "" ) ;
Title = substitute ( Title, "/", "" ) ;
Title = substitute ( Title, "\\", "" ) ;
string ext = regex_replace("^(.+/)(.+\.)(.+)$", SourceFile, "\3");
defname = Title + "." + ext;
end if
string newfn;
bool abort = false;
if ( int ( @get(ActiveModifierKeys)@ ) == 8 ) then
newfn = save_file_dialogue ("Hvor skal filen lagres?", desktop_directory(), defname) ;
if ( newfn == "" ) then
abort = true;
end if
else
newfn = desktop_directory() + defname;
end if
print format ( "Kilde:%s\nBestemmelse:%s\n", SourceFile,newfn ) ;
if ( ! abort ) then
string res = copy_file ( SourceFile, newfn ) ;
return res;
else
return "OK";
end if
end
The BSBO_SaveDocumentDesktop function saves a document from a server to the user's desktop folder. If the user holds the "ALT" key while activating this function, they will be prompted to choose a different save location.
This function is useful when you have a documents table in your database, and documents are stored on a file server in a folder structure. Instead of requiring the user to manually locate the document on the server, this function provides a convenient way to copy the file directly to their desktop.
Parameters:
- DocStore: The base path to the root of the document storage location on the server.
- ArchiveSubpath: The path to the document, as stored in the record of the documents table.
- Title: The name of the destination document. This can be provided without a file extension, as it will inherit the extension of the original file.
Example:
Set Variable [$res; ACFU_BSBO_SaveDocumentDesktop( "CommonFiles:DocArchive:"; "Customers/12345/Offers/Offer_123476.pdf"; "Todays-offer-customername")]
In this example, the function copies the file from:
/Volumes/CommonFiles/DocArchive/Customers/12345/Offers/Offer_123476.pdf
to:
/Users/henriette/Desktop/Todays-offer-customername.pdf
If the user holds the ALT key while running this function, a "Save As" dialog will appear with the filename "Todays-offer-customername.pdf" already filled in.
