public Windows.Storage.Streams.IInputStream GetNativeStream() { var action = esf.OpenForReadAsync(); action.Start(); action.Wait(); return(action.Result.AsInputStream()); }
private async Task LoadDatabaseFile(ExternalStorageFile file) { Stream stream = await file.OpenForReadAsync(); var info = new DatabaseInfo(); info.SetDatabase(stream, new DatabaseDetails { Name = file.Name.RemoveKdbx(), Type = SourceTypes.Updatable, Source = DatabaseUpdater.SDCARD_UPDATER, }); }
async void filePicker_OnDismiss(ExternalStorageFile file) { if (file != null) { StatusBox.Text = "Wait..."; // string incomingRouteFilename = Windows.Phone.Storage.SharedAccess.SharedStorageAccessManager.GetSharedFileName(file.Name); // StatusBox.Text = incomingRouteFilename; Stream photoToSave = await file.OpenForReadAsync(); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile photoFile = await localFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting); using (var photoOutputStream = await photoFile.OpenStreamForWriteAsync()) { await photoToSave.CopyToAsync(photoOutputStream); } StatusBox.Text = file.Path + file.Name; } }
/// <summary> /// Gets a file from SD Card /// </summary> /// <param name="sdfilePath"></param> /// <returns>File Stream</returns> public async Task <Stream> SDCard_ReadFile(string sdfilePath) { try { ExternalStorageDevice sdcard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); if (sdcard != null) { ExternalStorageFile file = await sdcard.GetFileAsync(sdfilePath); return(await file.OpenForReadAsync()); } else { MessageBox.Show("Please check SD Card"); return(null); } } catch (FileNotFoundException) { MessageBox.Show("File not found."); return(null); } }
async public void readfile(string filepath) { // enables progress indicator //ProgressIndicator indicator = SystemTray.ProgressIndicator; //if (indicator != null) //{ // //indicator.Text = "载入文件中 ..."; // //indicator.IsVisible = true; //} // Connect to the current SD card. ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); // If the SD card is present, add GPX files to the Routes collection. if (_sdCard != null) { try { // get file of the specific path ExternalStorageFile esf = await _sdCard.GetFileAsync(filepath); if (esf != null) { Debug.WriteLine("found file " + esf.Name); if (esf.Path.EndsWith(".txtx")) { // print its content Stream x = await esf.OpenForReadAsync(); byte[] buffer = new byte[x.Length]; x.Read(buffer, 0, (int)x.Length); x.Close(); string result = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length); //Debug.WriteLine(result); //this.title.Text = "阅读器"; //Debug.WriteLine("title changed"); //this.content.Text = result.Substring(0, 10000); //Debug.WriteLine("content changed"); this.contentString = result; // cut content into pages this.cutContentIntoPages(); // display first page this.currentPage = 0; this.displayCurrentPage(); } } Debug.WriteLine("done"); } catch (FileNotFoundException) { // No Routes folder is present. this.content.Text = "Error loading file, reason: file not found"; Debug.WriteLine("file not found."); } } else { // No SD card is present. Debug.WriteLine("The SD card is mssing."); } }