@@ -62,19 +62,41 @@ private async void PickMany(object sender, EventArgs e)
6262 await OnFilesPickedAsync ( files ) ;
6363 }
6464
65- private async void Save ( object sender , EventArgs e )
65+ MemoryStream GetContentStream ( )
6666 {
6767 var bytes = Encoding . UTF8 . GetBytes ( TextEditor . Text ?? "" ) ;
68- using var memory = new MemoryStream ( bytes ) ;
68+ return new MemoryStream ( bytes ) ;
69+ }
70+
71+ private async void Save ( object sender , EventArgs e )
72+ {
73+ using var memory = GetContentStream ( ) ;
6974
70- var result = await picker . SaveFileAsync ( new ( "text.txt" , memory )
75+ var result = await picker . SaveFileAsync ( new SaveFileOptions ( "text.txt" , memory )
7176 {
7277 AndroidMimeType = "text/plain" ,
73- WindowsFileTypes = ( "Text files" , new ( ) { ".txt" , } )
78+ WindowsFileTypes = ( "Text files" , [ ".txt" , ] )
7479 } ) ;
7580
7681 await DisplayAlert ( "File Saved" , result ? "File saved successfully." : "File save cancelled." , "OK" ) ;
7782 }
7883
84+ private async void DeferredSave ( object sender , EventArgs e )
85+ {
86+ // Simulate generating content
87+ async Task < Stream > streamFn ( )
88+ {
89+ await Task . Delay ( 2000 ) ;
90+ return GetContentStream ( ) ;
91+ }
92+
93+ var result = await picker . SaveFileAsync ( new DeferredSaveFileOptions ( "deferred.txt" , streamFn )
94+ {
95+ AndroidMimeType = "text/plain" ,
96+ WindowsFileTypes = ( "Text files" , [ ".txt" , ] )
97+ } ) ;
98+
99+ await DisplayAlert ( "File Saved" , result ? "File saved successfully." : "File save cancelled." , "OK" ) ;
100+ }
79101}
80102
0 commit comments