public static void SaveFile(string content) { #if __ANDROID__ //Email or cloud Android.Content.Intent intent = new Android.Content.Intent(Android.Content.Intent.ActionSend); intent.SetType("plain/text"); intent.PutExtra(Android.Content.Intent.ExtraSubject, "Logging"); intent.PutExtra(Android.Content.Intent.ExtraText, content); Forms.Context.StartActivity(intent); #elif __IOS__ //Email or cloud #else //Anywhere var documentpicker = new Windows.Storage.Pickers.FileSavePicker(); documentpicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; documentpicker.FileTypeChoices.Add("Comma seperated files.", new List <string>() { ".csv" }); documentpicker.SuggestedFileName = "Logfile"; documentpicker.PickSaveFileAsync().AsTask().ContinueWith((Task <Windows.Storage.StorageFile> resutl) => { var file = resutl.Result; Windows.Storage.FileIO.WriteTextAsync(file, content); }); #endif }
public void Share_Simple_Text_File_Test() { // Save a local cache data directory file var file = CreateFile(FileSystem.AppDataDirectory, "share-test.txt"); // Make sure it is where we expect it to be Assert.False(FileProvider.IsFileInPublicLocation(file)); // Actually get a safe shareable file uri var shareableUri = FileSystemUtils.GetShareableFileUri(new ReadOnlyFile(file)); // Launch an intent to let tye user pick where to open this content var intent = new Android.Content.Intent(Android.Content.Intent.ActionSend); intent.SetType("text/plain"); intent.PutExtra(Android.Content.Intent.ExtraStream, shareableUri); intent.PutExtra(Android.Content.Intent.ExtraTitle, "Title Here"); intent.SetFlags(Android.Content.ActivityFlags.GrantReadUriPermission); var intentChooser = Android.Content.Intent.CreateChooser(intent, "Pick something"); Platform.CurrentActivity.StartActivity(intentChooser); }