Skip to content

Commit a876522

Browse files
IceOnlytwityde
andauthored
External File Storage: Allow to suggest a filename in SaveFile (#3273)
<!-- Thank you for submitting a Pull Request. If you're new to contributing to BCApps please read our pull request guideline below * https://github.com/microsoft/BCApps/Contributing.md --> #### Summary <!-- Provide a general summary of your changes --> Allows to predefine the FileName: ``` trigger OnAction() var ExternalFileStorage: Codeunit "External File Storage"; Path: Text; begin ExternalFileStorage.Initialize("File Scenario"::Default); Path := ExternalFileStorage.SaveFile('2023', 'Invoice_1234', 'pdf', 'Save invoice...'); end; ``` ![image](https://github.com/user-attachments/assets/4835956d-5287-49df-b3f1-5bb45375b27d) #### Work Item(s) <!-- Add the issue number here after the #. The issue needs to be open and approved. Submitting PRs with no linked issues or unapproved issues is highly discouraged. --> Fixes #3272 Fixes [AB#571521](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/571521) Co-authored-by: Thomas Williamson <[email protected]>
1 parent d5f024c commit a876522

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/System Application/App/External File Storage/src/FileStorage/ExternalFileStorage.Codeunit.al

+16-3
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ codeunit 9454 "External File Storage"
224224
var
225225
DefaultSaveFileTitleLbl: Label 'Save as';
226226
begin
227-
exit(SaveFile(Path, FileExtension, DefaultSaveFileTitleLbl));
227+
exit(SaveFile(Path, '', FileExtension, DefaultSaveFileTitleLbl));
228228
end;
229229

230230
/// <summary>
@@ -236,7 +236,20 @@ codeunit 9454 "External File Storage"
236236
/// <returns>Returns the selected file path.</returns>
237237
procedure SaveFile(Path: Text; FileExtension: Text; DialogTitle: Text): Text
238238
begin
239-
exit(ExternalFileStorageImpl.SaveFile(Path, FileExtension, DialogTitle));
239+
exit(SaveFile(Path, '', FileExtension, DialogTitle));
240+
end;
241+
242+
/// <summary>
243+
/// Opens a save to dialog.
244+
/// </summary>
245+
/// <param name="Path">Start path of the dialog.</param>
246+
/// <param name="FileNameSuggestion">Suggested file name for the dialog.</param>
247+
/// <param name="FileExtension">The file extension without dot (like pdf or txt).</param>
248+
/// <param name="DialogTitle">Title of the selection dialog.</param>
249+
/// <returns>Returns the selected file path.</returns>
250+
procedure SaveFile(Path: Text; FileNameSuggestion: Text; FileExtension: Text; DialogTitle: Text): Text
251+
begin
252+
exit(ExternalFileStorageImpl.SaveFile(Path, FileNameSuggestion, FileExtension, DialogTitle));
240253
end;
241254

242255
/// <summary>
@@ -246,4 +259,4 @@ codeunit 9454 "External File Storage"
246259
begin
247260
ExternalFileStorageImpl.BrowseAccount();
248261
end;
249-
}
262+
}

src/System Application/App/External File Storage/src/FileStorage/ExternalFileStorageImpl.Codeunit.al

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ codeunit 9455 "External File Storage Impl."
184184
exit(CombinePath(TempFileAccountContent."Parent Directory", TempFileAccountContent.Name));
185185
end;
186186

187-
procedure SaveFile(Path: Text; FileExtension: Text; DialogTitle: Text): Text
187+
procedure SaveFile(Path: Text; FileNameSuggestion: Text; FileExtension: Text; DialogTitle: Text): Text
188188
var
189189
StorageBrowser: Page "Storage Browser";
190190
FileName, FileNameWithExtension : Text;
@@ -199,7 +199,7 @@ codeunit 9455 "External File Storage Impl."
199199

200200
StorageBrowser.SetPageCaption(DialogTitle);
201201
StorageBrowser.SetFileAccount(TempCurrFileAccount);
202-
StorageBrowser.EnableSaveFileLookupMode(Path, FileExtension);
202+
StorageBrowser.EnableSaveFileLookupMode(Path, FileNameSuggestion, FileExtension);
203203
if StorageBrowser.RunModal() <> Action::LookupOK then
204204
exit('');
205205

src/System Application/App/External File Storage/src/Lookup/StorageBrowser.Page.al

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@ page 9455 "Storage Browser"
161161
BrowseFolder(Path);
162162
end;
163163

164-
internal procedure EnableSaveFileLookupMode(Path: Text; FileExtension: Text)
164+
internal procedure EnableSaveFileLookupMode(Path: Text; FileNameSuggestion: Text; FileExtension: Text)
165165
var
166166
FileFilterTok: Label '*.%1', Locked = true;
167167
begin
168168
ShowFileName := true;
169169
FileFilter := StrSubstNo(FileFilterTok, FileExtension);
170+
SaveFileName := FileNameSuggestion;
170171
EnableLookupMode();
171172
BrowseFolder(Path);
172173
end;
@@ -204,4 +205,4 @@ page 9455 "Storage Browser"
204205
begin
205206
FileAccountBrowserMgt.BrowseFolder(Rec, Path, CurrentPath, DoNotLoadFiles, FileFilter);
206207
end;
207-
}
208+
}

0 commit comments

Comments
 (0)