Click or drag to resize
GDStorageFolderTryGetItemAsync Method
Tries to get the file or folder with the specified name from the current folder. Returns null instead of raising an exception if the specified file or folder is not found.

Namespace:  GD
Assembly:  GD (in GD.dll) Version: 255.255.255.255
Syntax
public IAsyncOperation<IGDStorageItem> TryGetItemAsync(
	string name
)

Parameters

name
Type: SystemString
The name (or path relative to the current folder) of the file or folder to get.

Return Value

Type: IAsyncOperationIGDStorageItem

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.

Implements

IGDStorageFolder2TryGetItemAsync(String)
Exceptions
ExceptionCondition
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.
Remarks
Call the TryGetItemAsync(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 an Exception. If the file or folder can't be found, TryGetItemAsync returns null instead of raising an exception.
Examples
The following example shows how to try to get a single file or folder from the current folder, or to check whether the file or folder exists, by calling the TryGetItemAsync(String) method.
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.");
See Also