/// <summary> /// Creates a copy of the file in the specified folder. /// </summary> /// <param name="destinationFolder">The destination folder where the copy of the file is created.</param> /// <returns></returns> public Task <StorageFile> CopyAsync(IStorageFolder destinationFolder) { #if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE return(Task.Run <StorageFile>(async() => { var f = await _file.CopyAsync((Windows.Storage.StorageFolder)((StorageFolder)destinationFolder)); return f == null ? null : new StorageFile(f); })); #else return(CopyAsync(destinationFolder, global::System.IO.Path.GetFileName(Path))); #endif }
public async Task <string> GetCopiedFilePath(string copyToDirectory, string fileNameWithoutExtension) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); if (file == null) { return(null); } //We only have temporary access to the file we get from the file picker, so need to copy it to //our new location inside this method instead of doing it later in the shared code. var copyToFolder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(copyToDirectory); var copiedFile = await file.CopyAsync(copyToFolder, fileNameWithoutExtension + System.IO.Path.GetExtension(file.Path), Windows.Storage.NameCollisionOption.ReplaceExisting); var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(copiedFile); return(copiedFile.Path); }
private async void UploadImage_BTN_Click(object sender, RoutedEventArgs e) { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { // Application now has read/write access to the picked file userInput.Text = "Picked photo: " + file.Name; string newPic = "ProfilePic" + file.FileType; var storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var newPicFile = await file.CopyAsync(storageFolder, newPic, Windows.Storage.NameCollisionOption.ReplaceExisting); image_box.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new System.Uri(newPicFile.Path)); } else { userInput.Text = "Operation cancelled."; } }
private async void SelectPhoto() { var picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".png"); Windows.Storage.StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { // Application now has read/write access to the picked file UploadPhoto.Content = "Picked photo: " + file.Name; } else { UploadPhoto.Content = "Operation cancelled."; } Windows.Storage.StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder; await file.CopyAsync(folder, file.Name); string filename = file.Name; setPhotoName(filename); }
public static async Task <string> CopySightFileAsync(string itemId, Windows.Storage.StorageFile sourceFile) { string recordFilesPath = Path.Combine(await GetSightFilesPathAsync(), itemId); Windows.Storage.StorageFolder filesFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync(recordFilesPath, Windows.Storage.CreationCollisionOption.OpenIfExists); var targetFile = await sourceFile.CopyAsync(filesFolder, sourceFile.Name, Windows.Storage.NameCollisionOption.ReplaceExisting); return(targetFile.Path); }
public static async System.Threading.Tasks.Task <string> CacheFileAsync(string sourceFilePath) { string fileName = Path.GetFileName(sourceFilePath); Windows.Storage.StorageFile sourceStorageFile = UwpFileBrowser.LastOpenFile; Windows.Storage.StorageFolder cacheStorageFolder = Windows.Storage.ApplicationData.Current.LocalCacheFolder; var cacheStorageFile = await sourceStorageFile.CopyAsync( cacheStorageFolder, fileName, Windows.Storage.NameCollisionOption.ReplaceExisting); string cacheFilePath = cacheStorageFile.Path; return(cacheFilePath); }
async internal void CopyImage(Windows.Storage.IStorageItem file, Windows.Storage.StorageFolder imageFolder) { try { Windows.Storage.StorageFile sFile = (Windows.Storage.StorageFile)file; await sFile.CopyAsync(imageFolder, sFile.Name); WriteMessageText(sFile.Name + " copied.\n"); } catch (Exception e) { WriteMessageText("Failed to copy file.\n" + e.Message + "\n"); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { // получаем имя базы данных string databaseName = PD_Diary.App.DATABASE_NAME; if (await Windows.Storage.ApplicationData.Current.LocalFolder.TryGetItemAsync(databaseName) == null) { // копируем бд из папки Assets Windows.Storage.StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync($"Assets\\{databaseName}"); await databaseFile.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder); } // .....остальное содержимое метода // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (!(Window.Current.Content is Frame rootFrame)) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; Xamarin.Forms.Forms.Init(e); if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }
/// <summary> /// Copy a file in a folder with a new name /// </summary> public static async System.Threading.Tasks.Task <Windows.Storage.StorageFile> CopyFileToFolder(string path, string folderName, string desiredNewName) { try { Windows.Storage.StorageFolder folder = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync(folderName); if (folder != null) { Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromPathAsync(path); if (file != null) { return(await file.CopyAsync(folder, desiredNewName)); } } } catch (Exception Ex) { System.Diagnostics.Debug.WriteLine("Exception while copying file: " + Ex.Message); } return(null); }
public void CopyImageToLocalImageFolder(Windows.Storage.StorageFile srtFile) { var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var targetFolder = default(Windows.Storage.StorageFolder); var targetItem = localFolder.TryGetItemAsync(AlarmManager.ImagesFolderName).AsTask().GetAwaiter().GetResult(); // folder (or file!!!) does not exist if (targetItem == null) { targetFolder = localFolder.CreateFolderAsync(AlarmManager.ImagesFolderName).AsTask().GetAwaiter().GetResult(); } else { targetFolder = targetItem as Windows.Storage.StorageFolder; } // copy files from package folder to target folder so we are able to play them in toasts. var installationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; srtFile.CopyAsync(targetFolder, srtFile.Name, Windows.Storage.NameCollisionOption.ReplaceExisting) .AsTask().GetAwaiter().GetResult(); }
// Throws when the file already exists. private static Windows.Foundation.IAsyncOperation <Windows.Storage.StorageFile> CopyDbAsync(Windows.Storage.StorageFile srcDbFile, string destDbFileName) { // This implementation is closely related to ResolveDbFilePath. return(srcDbFile.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, destDbFileName, Windows.Storage.NameCollisionOption.FailIfExists)); }