本文整理汇总了C#中Windows.Storage.StorageFolder.TryGetItemAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.TryGetItemAsync方法的具体用法?C# StorageFolder.TryGetItemAsync怎么用?C# StorageFolder.TryGetItemAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.TryGetItemAsync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAsync
public async static Task LoadAsync(this InkCanvas inkCanvas, string fileName, StorageFolder folder = null)
{
folder = folder ?? ApplicationData.Current.TemporaryFolder;
var file = await folder.TryGetItemAsync(fileName) as StorageFile;
if (file != null)
{
try
{
using (var stream = await file.OpenSequentialReadAsync())
{
await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(stream);
}
}
catch { }
}
}
示例2: DeleteFolder
/// <summary>
/// Deletes folder even if it contains read only files
/// </summary>
/// <param name="path"></param>
public async static Task<bool> DeleteFolder(StorageFolder baseDir, string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return false;
}
var folder = await baseDir.TryGetItemAsync(path) as StorageFolder;
if (folder == null)
{
return false;
}
foreach (var file in await folder.GetFilesAsync())
{
await SafeFileDelete(file.Path);
}
await folder.DeleteAsync();
return true;
}
示例3: OpenComicCollection
private async void OpenComicCollection(StorageFolder chosenFolder, StorageFolder collections)
{
LoadingGridVisible(true);
List<StorageFile> files = await RecursivelySearchForFiles(chosenFolder);
StorageFolder collectionFolder = (StorageFolder)await collections.TryGetItemAsync(chosenFolder.Name);
if (collectionFolder == null)
{
collectionFolder = await collections.CreateFolderAsync(chosenFolder.Name);
}
else
{
ShowWarning("Collection already exist!", "Adding new comics");
}
foreach (StorageFile sourceFile in files)
{
StorageFolder destFolder = (StorageFolder)await collectionFolder.TryGetItemAsync(sourceFile.Name);
if (destFolder == null)
{
destFolder = await collectionFolder.CreateFolderAsync(sourceFile.Name);
try
{
DefaultViewModel["LoadingFile"] = sourceFile.Name;
if (sourceFile.FileType.Equals("cbz") || sourceFile.FileType.Equals(".cbz"))
await FolderZip.UnZipFile(sourceFile, destFolder);
else if (sourceFile.FileType.Equals("cbr") || sourceFile.FileType.Equals(".cbr"))
await FolderZip.UnRarFile(sourceFile, destFolder);
}
catch (InvalidFormatException exception)
{
ShowWarning("Error opening file:" + sourceFile.Name, "Please try again");
}
}
LoadingBar.Value += (1.0 / files.Count()) * 100;
}
await CreateCollectionTiles();
CollectionViews.Clear();
foreach (CollectionTile tile in CollectionTiles)
{
CollectionViews.Add(new CollectionView(tile));
}
defaultViewModel["ComicTiles"] = ComicTiles;
defaultViewModel["CollectionViews"] = CollectionViews;
LoadingGridVisible(false);
}
示例4: ContinueAfterExportBinderPickerAsync
private async Task ContinueAfterExportBinderPickerAsync(StorageFolder toDir, string dbName, Briefcase bc)
{
bool isExported = false;
try
{
if (bc != null && toDir != null)
{
_animationStarter.StartAnimation(AnimationStarter.Animations.Updating);
if (string.IsNullOrWhiteSpace(dbName) /*|| _dbNames?.Contains(dbName) == false */|| toDir == null) return;
var fromDirectory = await Briefcase.BindersDirectory
.GetFolderAsync(dbName)
.AsTask().ConfigureAwait(false);
if (fromDirectory == null) return;
// what if you copy a directory to an existing one? Shouldn't you delete the contents first? No! But then, shouldn't you issue a warning?
var toDirectoryTest = await toDir.TryGetItemAsync(dbName).AsTask().ConfigureAwait(false);
if (toDirectoryTest != null)
{
var confirmation =
await UserConfirmationPopup.GetInstance().GetUserConfirmationBeforeExportingBinderAsync(CancToken).ConfigureAwait(false);
if (CancToken.IsCancellationRequested) return;
if (confirmation == null || confirmation.Item1 == false || confirmation.Item2 == false) return;
}
isExported = await bc.ExportBinderAsync(dbName, fromDirectory, toDir).ConfigureAwait(false);
}
}
catch (Exception ex)
{
await Logger.AddAsync(ex.ToString(), Logger.FileErrorLogFilename, Logger.Severity.Info).ConfigureAwait(false);
}
finally
{
_animationStarter.EndAllAnimations();
if (!CancToken.IsCancellationRequested)
_animationStarter.StartAnimation(isExported
? AnimationStarter.Animations.Success
: AnimationStarter.Animations.Failure);
IsExportingBinder = false;
}
}
示例5: FileDoesNotExistAsync
private static async Task<bool> FileDoesNotExistAsync(string fileName, StorageFolder imagesFolder)
{
return await imagesFolder.TryGetItemAsync(fileName) == null;
}
示例6: initialize
//Initialize "devices" list and Channel and volumeDevices
public async Task initialize(StorageFolder devices_folder_)
{
is_initialized = true;
// Device Manager Metadata Initialization
devices_folder = devices_folder_;
devices_info_file = (StorageFile) await devices_folder.TryGetItemAsync("devices_info.txt");
if(devices_info_file == null)
{
System.Diagnostics.Debug.WriteLine("No Devices info file!");
return;
}
IList<string> input = await FileIO.ReadLinesAsync(devices_info_file);
int num_channel_devices = Convert.ToInt32(input[0]);
int cur_index = 1;
String device_name;
StorageFile cur_device_input_file;
// Channel Device Initialization
for(int i = 0; i < num_channel_devices; ++i)
{
device_name = input[cur_index++];
try
{
cur_device_input_file = (StorageFile)await get_input_file_from_name(device_name, 'c');
ChannelDevice c_device = new ChannelDevice(device_name, cur_device_input_file);
channel_devices.Add(c_device);
}
catch(Exception except)
{
System.Diagnostics.Debug.WriteLine(except.Message);
}
}
// Get Current Channel Device
int chan_index = 0;
bool found = false;
string cur_chan_device_name = input[cur_index++];
foreach(ChannelDevice cur in channel_devices)
{
if(cur.get_name().Equals(cur_chan_device_name))
{
found = true;
break;
}
chan_index++;
}
if (!found)
{
// Throw Exception about channel device not found
}
else
{
channelController = channel_devices[chan_index];
await channelController.initialize();
}
// Volume Device Initialization
int num_vol_devices = Convert.ToInt32(input[cur_index++]);
for(int i = 0; i < num_vol_devices; ++i)
{
device_name = input[cur_index++];
cur_device_input_file = await get_input_file_from_name(device_name, 'v');
VolumeDevice v_device = new VolumeDevice(device_name, cur_device_input_file);
volume_devices.Add(v_device);
}
int vol_index = 0;
string cur_vol_device_name = input[cur_index++];
found = false;
foreach(VolumeDevice cur_v in volume_devices)
{
if(cur_v.get_name().Equals(cur_vol_device_name))
{
found = true;
break;
}
vol_index++;
}
if(!found)
{
// TODO: Throw Error
}
else
{
volumeController = volume_devices[vol_index];
await volumeController.initialize();
}
}
示例7: DirectoryExists
public static async Task<bool> DirectoryExists(StorageFolder baseDir, string path)
{
try
{
return (await baseDir.TryGetItemAsync(path)) != null;
}
catch (FileNotFoundException)
{
return false;
}
}
示例8: FileExists
public static async Task<bool> FileExists(StorageFolder baseFolder, string fileName)
{
if (baseFolder == null || string.IsNullOrWhiteSpace(fileName))
{
return false;
}
try
{
var storageItem = await baseFolder.TryGetItemAsync(fileName);
return storageItem != null && storageItem.IsOfType(StorageItemTypes.File);
}
catch (Exception)
{
return false;
}
}
示例9: GetFile
public static async Task<StorageFile> GetFile(StorageFolder folder, string path)
{
if (string.IsNullOrWhiteSpace(path))
{
return null;
}
try
{
return await folder.TryGetItemAsync(Path.GetFileName(path)) as StorageFile;
}
catch (Exception)
{
return null;
}
}
示例10: IfFolderExistsAsync
/// <summary>
/// It checks if the specified folder exists.
/// </summary>
/// <param name="storageFolder">The container folder</param>
/// <param name="subFolderName">The sub folder name</param>
/// <returns></returns>
private static async Task<bool> IfFolderExistsAsync(StorageFolder storageFolder, string subFolderName)
{
var storageItem = await storageFolder.TryGetItemAsync(subFolderName);
return storageItem != null && storageItem.IsOfType(StorageItemTypes.Folder);
}
示例11: IfStorageItemExist
public async Task<bool> IfStorageItemExist(StorageFolder folder, string itemName)
{
try
{
IStorageItem item = await folder.TryGetItemAsync(itemName);
return (item != null);
}
catch (Exception)
{
// Should never get here
return false;
}
}
示例12: _GetFolderAsync
private static async Task<StorageFolder> _GetFolderAsync(string name, StorageFolder parent)
{
var item = await parent.TryGetItemAsync(name).AsTask().DontMarshall();
return item as StorageFolder;
}
示例13: GetIfFileExistsAsync
public static async Task<StorageFile> GetIfFileExistsAsync(string path, StorageFolder folder)
{
var parts = path.Split('/');
var fileName = parts.Last();
if (parts.Length > 1)
{
folder =
await GetFolderAsync(path.Substring(0, path.Length - fileName.Length), folder).ConfigureAwait(false);
}
if (folder == null)
{
return null;
}
return await folder.TryGetItemAsync(fileName).AsTask().DontMarshall() as StorageFile;
}
示例14: _GetFolderAsync
private static async Task<StorageFolder> _GetFolderAsync(string name, StorageFolder parent)
{
var item = await parent.TryGetItemAsync(name).AsTask().ConfigureAwait(false);
return item as StorageFolder;
}