本文整理汇总了C#中Windows.Storage.StorageFile.CopyAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.CopyAsync方法的具体用法?C# StorageFile.CopyAsync怎么用?C# StorageFile.CopyAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFile
的用法示例。
在下文中一共展示了StorageFile.CopyAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePageFiles
public async static Task CreatePageFiles(StorageFile fileToCopy, Guid pageId)
{
var localFolder = ApplicationData.Current.LocalFolder;
await fileToCopy.CopyAsync(localFolder, pageId.ToString() + ".jpg");
await fileToCopy.CopyAsync(localFolder, pageId.ToString() + "_backup" + ".jpg");
}
示例2: ParseData
public async void ParseData(StorageFile file)
{
try
{
if (!await FileUtil.DirExistsAsync(ConstantsAPI.SDK_TEMP_DIR_PATH))
{
await FileUtil.CreateDirAsync(ConstantsAPI.SDK_TEMP_DIR_PATH);
}
var folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(ConstantsAPI.SDK_TEMP_DIR_PATH);
var copyFile = await file.CopyAsync(folder, "wp.wechat", NameCollisionOption.ReplaceExisting);
if (await FileUtil.FileExistsAsync(ConstantsAPI.SDK_TEMP_FILE_PATH))
{
TransactData data = await TransactData.ReadFromFileAsync(ConstantsAPI.SDK_TEMP_FILE_PATH);
if (!data.ValidateData())
{
//MessageBox.Show("数据验证失败");
}
else if (!data.CheckSupported())
{
//MessageBox.Show("当前版本不支持该请求");
}
else if (data.Req != null)
{
if (data.Req.Type() == ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX)
{
OnGetMessageFromWXRequest(data.Req as GetMessageFromWX.Req);
}
else if (data.Req.Type() == 4)
{
OnShowMessageFromWXRequest(data.Req as ShowMessageFromWX.Req);
}
}
else if (data.Resp != null)
{
if (data.Resp.Type() == 1)
{
OnSendAuthResponse(data.Resp as SendAuth.Resp);
}
else if (data.Resp.Type() == 2)
{
OnSendMessageToWXResponse(data.Resp as SendMessageToWX.Resp);
}
else if (data.Resp.Type() == 5)
{
OnSendPayResponse(data.Resp as SendPay.Resp);
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
//MessageBox.Show(exception.Message);
}
}
示例3: SaveImageAsync
private async void SaveImageAsync(StorageFile file)
{
if (file != null)
{
StorageFile newImageFile = await file.CopyAsync(ApplicationData.Current.LocalFolder, Guid.NewGuid().ToString());
App.MainViewModel.SelectedBBQRecipe.ImagePath = newImageFile.Path;
}
}
示例4: CreateFromStorageFileAsync
public static async Task<Note> CreateFromStorageFileAsync(StorageFile sf, NoteKind k, string name, string desc, string classId) {
var docProps = await sf.Properties.GetDocumentPropertiesAsync();
var imgProps = await sf.Properties.GetImagePropertiesAsync();
imgProps.DateTaken = DateTime.Now;
docProps.Title = name;
docProps.Comment = desc;
await docProps.SavePropertiesAsync();
await imgProps.SavePropertiesAsync();
var fileName = string.Format("{0}_{1}_{2}.{3}", classId, imgProps.DateTaken.ToString("MM-dd-yyyy ss-fff"), k.ToString().ToLower(), k == NoteKind.Txt ? "txt" : k == NoteKind.Img ? "jpg" : "mp4");
var newFile = await sf.CopyAsync(await ApplicationData.Current.RoamingFolder.CreateFolderAsync("Notes", CreationCollisionOption.OpenIfExists), fileName, NameCollisionOption.ReplaceExisting);
return await CreateFromStorageFileAsync(newFile);
}
示例5: UnzipKmz
// http://stackoverflow.com/questions/36728529/extracting-specific-file-from-archive-in-uwp
private async Task UnzipKmz(StorageFile kmzFile)
{
StorageFolder folder = ApplicationData.Current.TemporaryFolder;
// Clear in temporary folder
ClearTempFolder();
// Need to copy file to temporary folder
StorageFile temp = await kmzFile.CopyAsync(folder);
using (ZipArchive archive = ZipFile.OpenRead(temp.Path))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.ToString() == "doc.kml")
{
entry.ExtractToFile(Path.Combine(folder.Path, entry.FullName));
// Set KML file
kmlFile = await folder.GetFileAsync("doc.kml");
}
}
}
}
示例6: SaveFiletoLocalAsync
public static async Task<Uri> SaveFiletoLocalAsync(string path, StorageFile file, string desiredName)
{
var local = ApplicationData.Current.LocalFolder;
try
{
var folder = await local.CreateFolderAsync(path, CreationCollisionOption.OpenIfExists);
await file.CopyAsync(folder, desiredName + file.FileType, NameCollisionOption.ReplaceExisting);
return new Uri("ms-appdata:///local/" + path.Replace("\\", "/") + '/' + desiredName + file.FileType);
}
catch (Exception)
{
return null;
}
}
示例7: ChooseBackgroundImage
private async void ChooseBackgroundImage(StorageFile file)
{
String filename = "menuBackground.png";
await file.CopyAsync(ApplicationData.Current.LocalFolder as IStorageFolder, filename, NameCollisionOption.ReplaceExisting);
AppSettings.BackgroundImage = filename;
LoadBackgroundImage();
}
示例8: FileOpenPicker_Continuation
private async void FileOpenPicker_Continuation(StorageFile file)
{
if (file != null)
{
var destFile = await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting);
var userPhoto = new UserPhotoDataItem() { Title = destFile.Name};
userPhoto.SetImage(destFile.Path);
item.UserPhotos.Add(userPhoto);
}
}
示例9: SaveUserAvatarFile
/// <summary>
/// Copies the user's avatar's file to it's place (avatars subfolder).
/// </summary>
/// <param name="file">The user's avatar's file.</param>
/// <returns>The copy of the file.</returns>
private async Task<StorageFile> SaveUserAvatarFile(StorageFile file)
{
var copy = await file.CopyAsync(_avatarsFolder);
await copy.RenameAsync(ToxModel.Instance.Id.PublicKey + ".png", NameCollisionOption.ReplaceExisting);
return copy;
}
示例10: ExecuteSavePictureCommand
private async void ExecuteSavePictureCommand(StorageFile file)
{
try
{
if (file != null)
{
// Copy the file into local folder
await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.GenerateUniqueName);
// Save in the ToDoItem
TodoItem.ImageUri = new Uri("ms-appdata:///local/" + file.Name);
}
}
finally { Busy = false; }
}
示例11: imgfolder
private async Task<string> imgfolder(file_storage temp, StorageFile file) //StorageFile file)
{
//string str = _file.Name;
//StorageFolder image = null;
//try
//{
// image = await _folder.GetFolderAsync(str);
//}
//catch
//{
//}
//if (image == null)
//{
// image = await _folder.CreateFolderAsync(str, CreationCollisionOption.OpenIfExists);
//}
string str;
file = await file.CopyAsync(temp.folder, file.Name, NameCollisionOption.GenerateUniqueName);
if ((file.FileType == ".png") || (file.FileType == ".jpg") || (file.FileType == ".gif"))
{
str = $"![这里写图片描述]({temp.folder}/{file.Name})\n\n";
return str;
}
str = $"[{file.Name}]({temp.folder}/{file.Name})\n\n";
return str;
}
示例12: SetImageSource
public async Task SetImageSource(StorageFile sourceFile)
{
var tempFolder = ApplicationData.Current.TemporaryFolder;
m_ext = sourceFile.Name.Substring(sourceFile.Name.LastIndexOf('.'));
// original full size image
//var img = await sourceFile.CopyAsync(tempFolder, m_filename + "a" + m_ext, NameCollisionOption.ReplaceExisting);
// cropped image will be stored here
//img = await sourceFile.CopyAsync(tempFolder, m_filename + m_ext, NameCollisionOption.ReplaceExisting);
//ImageSource = img.Path;
var f = tempFolder.Path + "\\";
var i1 = m_filename + "a" + m_ext;
var i2 = m_filename + m_ext;
// copy new source to temp folder
await sourceFile.CopyAsync(tempFolder, i1, NameCollisionOption.ReplaceExisting);
// crop image to target size
await Common.CropHelper.CropImageAsync(f + i1, f + i2, 1, new Rect(0, 0, ImageWidth, ImageHeight), Common.CropType.GetLargestRect);
ImageSource = CreateSource(f + i2);
}
示例13: CopyFileToFolderOnStorageAsync
/// <summary>
/// Copies a file to the first folder on a storage.
/// </summary>
/// <param name="sourceFile"></param>
/// <param name="storage"></param>
async private Task CopyFileToFolderOnStorageAsync(StorageFile sourceFile, StorageFolder storage)
{
var storageName = storage.Name;
// Construct a folder search to find sub-folders under the current storage.
// The default (shallow) query should be sufficient in finding the first level of sub-folders.
// If the first level of sub-folders are not writable, a deep query + recursive copy may be needed.
var folders = await storage.GetFoldersAsync();
if (folders.Count > 0)
{
var destinationFolder = folders[0];
var destinationFolderName = destinationFolder.Name;
rootPage.NotifyUser("Trying the first sub-folder: " + destinationFolderName + "...", NotifyType.StatusMessage);
try
{
var newFile = await sourceFile.CopyAsync(destinationFolder, sourceFile.Name, NameCollisionOption.GenerateUniqueName);
rootPage.NotifyUser("Image " + newFile.Name + " created in folder: " + destinationFolderName + " on " + storageName, NotifyType.StatusMessage);
}
catch (Exception e)
{
rootPage.NotifyUser("Failed to copy image to the first sub-folder: " + destinationFolderName + ", " + storageName + " may not allow sending files to its top level folders. Error: " + e.Message, NotifyType.ErrorMessage);
}
}
else
{
rootPage.NotifyUser("No sub-folders found on " + storageName + " to copy to", NotifyType.StatusMessage);
}
}
示例14: SaveBitmapToPictureLibrary
public async Task SaveBitmapToPictureLibrary(StorageFile image)
{
await image.CopyAsync(KnownFolders.PicturesLibrary);
}
示例15: SetPictureFile
public static async void SetPictureFile(StorageFile file)
{
// Delete the old picture.
if (_pictureFile != null)
{
await _pictureFile.DeleteAsync();
await file.CopyAsync(ApplicationData.Current.LocalFolder);
_pictureFile = file;
}
else
{
// Check if the file actually does exist.
try
{
StorageFile possibleFile = await ApplicationData.Current.LocalFolder.GetFileAsync(file.Name);
}
catch (Exception)
{
file.CopyAsync(ApplicationData.Current.LocalFolder);
_pictureFile = file;
}
}
}