GDStorageFolderGetItemAsync Method |
Namespace: GD
public IAsyncOperation<IGDStorageItem> GetItemAsync( string name )
When this method completes successfully, it returns an IGDStorageItem) that represents the specified file or folder.
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 |
---|---|
Exception | (C# equivalent: System.IO.FileNotFoundException) The specified item does not exist. Check the value of name. |
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. |
Call the IsOfType method of the IGDStorageItem interface to determine whether the returned item is a file or a folder.
To get a specific file without casting the return value, call the GetFileAsync(String) method. To get a specific folder without casting the return value, call the GetFolderAsync(String) method.
To try to get a file or folder by name, or to check whether a file or folder exists, without the need to handle a Exception, call the TryGetItemAsync(String) method.
using GD; // Get root folder of GD secure storage GDStorageFolder rootFolder = GDWindows.Instance.SecureFolder; // Create subfolder and a file var subFolder = await rootFolder.CreateFolderAsync("Subfolder"); var file = await subFolder.CreateFileAsync("File.txt"); // Get the subfolder var level1Folder = (GDStorageFolder)await rootFolder.GetItemAsync("Subfolder"); // Get the subfolder of the subfolder by providing a relative path. var level2File = (GDStorageFile)await rootFolder.GetItemAsync(@"Subfolder\File.txt");