Hello,
Welcome to Microsoft Q&A.
If you want to get a string from a StorageFileQueryResult
to show the information for logging, then you could create a method which accepts a parameter whose type is StorageFileQueryResult
, and return the string you needed from the StorageFileQueryResult
instance.
Or, if you want a better coupling, you could wrap a StorageFileQueryResult
instance and a ToString()
method in a single class.
Here is a presentation for the second idea:
public class MyStorageFileQueryResult
{
public StorageFileQueryResult storageFileQueryResult { get; set; }
public async Task<string> ToString()
{
//If your ToString() method is synchronous, you could create ToString() like this:
//public override string ToString()
string returnString = "StorageFile list:\n";
IReadOnlyList<StorageFile> fileList = await storageFileQueryResult.GetFilesAsync();
foreach (StorageFile file in fileList)
{
returnString += file.Name + "\n";
}
return returnString;
}
}
//A test
private async void Button_Click(object sender, RoutedEventArgs e)
{
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".jpg");
fileTypeFilter.Add(".png");
fileTypeFilter.Add(".bmp");
fileTypeFilter.Add(".gif");
var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
// Create query and retrieve files
MyStorageFileQueryResult query = new MyStorageFileQueryResult();
query.storageFileQueryResult= KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
string str =await query.ToString();
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.