PROCEDURE UploadMultipleFiles@1000000019(UploadToPath@1000000001 : Text[250];FileFilter@1000000005 : Text[30]) : Boolean; VAR BLOBRef@1000000002 : TEMPORARY Record 99008535; Strings@1000000004 : Codeunit 50020; Enumerator@1000000010 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.IEnumerator" RUNONCLIENT; ArrayList@1000000011 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.ArrayList" RUNONCLIENT; FileDialog@1000000007 : DotNet "'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Windows.Forms.OpenFileDialog" RUNONCLIENT; DialogResult@1000000006 : DotNet "'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Windows.Forms.DialogResult" RUNONCLIENT; FileInfo@1000000016 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileInfo" RUNONCLIENT; SelectedFile@1000000012 : Text[1024]; ToFilePath@1000000000 : Text[1024]; "3TierMgt"@1000000015 : Codeunit 419; ClientTempFileName@1000000017 : Text[1024]; FilesUploaded@1000000009 : Integer; BEGIN // ************************************************ Parameter definations ******************************************************** // UploadToPath -> Path of the folder in which user want to upload the file // FileFilter -> Examples All Files (*.*)|*.*, Text Files (*.txt)|*.txt, Excel (*.xl*)|*.xl* etc // ************************************************ Description ******************************************************** // This function open the file selector and user select the file that get uploaded into temporay BLOB field // blob then gets exported to UploadToPath with same file name as selected // ********************************************************************************************************************************* FileDialog := FileDialog.OpenFileDialog(); FileDialog.Multiselect := TRUE; FileDialog.Title := 'Select multiple files'; FileDialog.Filter := FileFilter; // Show multiple file selector DialogResult := FileDialog.ShowDialog(); ArrayList := ArrayList.ArrayList(); ArrayList.AddRange(FileDialog.FileNames()); Enumerator := ArrayList.GetEnumerator(); WHILE Enumerator.MoveNext() DO BEGIN CLEAR(BLOBRef.Blob); CLEAR(FileInStream); CLEAR(FileOutStream); CLEAR(FileInfo); SelectedFile := Enumerator.Current; // Select Current File FileInfo := FileInfo.FileInfo(SelectedFile); //Fileinfo is DotNet object // When doing silent upload(means no navision file selector), then file has to be in RTC's temp folder ClientTempFileName := "3TierMgt".ClientTempFileName('',Strings.TokenFromEnd(SelectedFile,'.')); FileInfo.CopyTo(ClientTempFileName); // MagicPath allow to hide selector dialog forUPLOADINTOSTREAM IF UPLOADINTOSTREAM('', "3TierMgt".Magicpath(), '', ClientTempFileName, FileInStream) THEN BEGIN // Create the drop file path ToFilePath := STRSUBSTNO('%1\%2',UploadToPath,FileInfo.Name); BLOBRef.Blob.CREATEOUTSTREAM(FileOutStream); COPYSTREAM(FileOutStream,FileInStream); BLOBRef.Blob.EXPORT(ToFilePath); // Not wrapping in IF condition because I want it to throw descriptive error. e.g permissions END; FilesUploaded += 1; // Removing the temp file FileInfo := FileInfo.FileInfo(ClientTempFileName); FileInfo.Delete(); END; IF (FilesUploaded>0) AND GUIALLOWED THEN BEGIN MESSAGE('%1 files uploaded out of %2',FilesUploaded,ArrayList.Count); EXIT(TRUE); END; END;