public async Task MoveFileAsync(StorageFile file, StorageFolder destinationFolder, string desiredNewFileName) { if (Exist(destinationFolder, desiredNewFileName)) { try { StorageFile fileToDelete = await destinationFolder.GetFileAsync(desiredNewFileName); await DeleteAsync(fileToDelete); } catch (Exception) { //TODO there is a known issue of the .net api; fix this when the api will be fixed } } await file.MoveAsync(destinationFolder,desiredNewFileName); }
//Download file from dropbox public async Task Download(string folder, string file) { try { using (var response = await dbx.Files.DownloadAsync(folder + "/" + file)) { string text = (await response.GetContentAsStringAsync()); //Debug.WriteLine(text); //Files in assets folder are read only therefore we can't directly create a file in that folder //alternatively create the file in MusicLibrary and move it to Assets/Books var musicFolder = Windows.Storage.KnownFolders.MusicLibrary; Windows.Storage.StorageFile textFile = await musicFolder.CreateFileAsync(file, Windows.Storage.CreationCollisionOption.ReplaceExisting); Windows.Storage.StorageFile getFile = await musicFolder.GetFileAsync(file); await Windows.Storage.FileIO.WriteTextAsync(getFile, text); //Move file to Assets/Books getFile = await musicFolder.GetFileAsync(file); var directory = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFolder assets = await directory.GetFolderAsync(@"Assets\Books"); await getFile.MoveAsync(assets, file, NameCollisionOption.ReplaceExisting); var message = new MessageDialog("Download Successful."); await message.ShowAsync(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); var message = new MessageDialog("Something went wrong, check your internet connection and try again."); await message.ShowAsync(); } }
public async Task<string> GetPictureFromCameraAsync() { var photo = new CameraCaptureUI(); photo.PhotoSettings.AllowCropping = true; photo.PhotoSettings.CroppedAspectRatio = new Size(1, 1); photo.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable; photo.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png; _recordStorageFile = await photo.CaptureFileAsync(CameraCaptureUIMode.Photo); if (_recordStorageFile != null) { var path = Path.Combine(StorageService.ImagePath); _url = string.Format("Image_{0}.{1}", Guid.NewGuid(), _recordStorageFile.FileType); var folder = await StorageFolder.GetFolderFromPathAsync(path); await _recordStorageFile.MoveAsync(folder, _url, NameCollisionOption.FailIfExists); return string.Format("{0}\\{1}",path, _url); } return ""; }
public static async Task MoveFileToLocalAsync(StorageFile backingFile) { await backingFile.MoveAsync(_localFolder, backingFile.Name, NameCollisionOption.GenerateUniqueName); }