GDStorageFolderTryGetItemAsync Method |
Namespace: GD
public IAsyncOperation<IGDStorageItem> TryGetItemAsync( string name )
When this method completes successfully, it returns an IGDStorageItem that represents the specified file or folder. If the specified file or folder is not found, this method returns null instead of raising an exception.
To work with the returned item, call the IsOfType method of the IGDStorageItem interface to determine whether the item is a file or a folder. Then cast the item to a GDStorageFolder or GDStorageFile.
Exception | Condition |
---|---|
AccessDeniedException | (C# equivalent: System.UnauthorizedAccessException) Secure storage was remotely wiped. |
InvalidArgumentException | (C# equivalent: System.ArgumentException) The path contains invalid characters, or the format of the path is incorrect. Check the value of name. |
using Windows.Storage; using System.Diagnostics; // For writing results to the Output window. using GD; ... // Get the path to the app's Assets folder. string root = GDWindows.Instance.SecureFolder.Path; string path = root + @"\Assets"; // Get the app's Assets folder. GDStorageFolder assetsFolder = await GDStorageFolder.GetFolderFromPathAsync(path); // Check whether an image with the specified scale exists. string imageName = "Logo.scale-140.png"; if (await assetsFolder.TryGetItemAsync(imageName) != null) Debug.WriteLine(imageName + " exists."); else // Return value of TryGetItemAsync is null. Debug.WriteLine(imageName + " does not exist.");