应用商店应用程序在我的图片中创建子文件夹

应用商店应用程序在我的图片中创建子文件夹

本文介绍了从 Windows 应用商店应用程序在我的图片中创建子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Windows 商店应用在我的图片"文件夹中创建文件夹结构.但是我好像没能通过第一关.

I'm trying to create a folder structure within My Pictures folder from a Windows store app. But I can't seem to get pass the first level.

我使用以下代码创建我的第一级文件夹:

I create my first level folder using the following code:

IAsyncOperation<StorageFolder> appFolder = Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync("AppPhotos");

if (appFolder==null)
{
    //Create folder
    appFolder = Windows.Storage.KnownFolders.PicturesLibrary.CreateFolderAsync("AppPhotos");
}

现在我想在这个调用 Level1 下创建另一个文件夹.

Now I want to create another folder below this call Level1.

我希望能够做到以下几点:

I was expecting to be able to do the following:

appFolder.CreateFolderAsync("Level1");

但我的 appFolder 中没有 CreateFolderAsync 方法.

But I don't have a CreateFolderAsync method from my appFolder.

那么,我如何创建该文件夹,然后我将如何选择它?

So, how can I create that Folder and then how would I then select it?

提前致谢

我正在使用 Visual Studio 2012、C#4.5、XAML,并且正在编写 Windows 商店应用程序.

I'm using Visual Studio 2012, C#4.5, XAML and I'm writing a windows store app.

推荐答案

您似乎错过了 async/await 革命,并假设获取文件夹的操作是文件夹.这应该有效:

You seem to have missed the async/await revolution there and assume the operation to get a folder is a folder. This should work:

var appFolder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync("AppPhotos");

if (appFolder == null)
{
    //Create folder
    appFolder = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFolderAsync("AppPhotos");
}

您还需要在上述代码所在的方法签名中添加 async 关键字,然后如果您的方法返回 T 类型的值 - 更改它返回Task,因此对于方法签名:

You also need to add the async keyword in the method signature wherever the above code is located and then also if your method returns a value of type T - change it to return Task<T>, so for method signature:

private void MyMethod()

你会把它改成

private async Task MyMethod()

如果您当前的签名是

private bool MyMethod()

你需要做的

private async Task<bool> MyMethod()

最后在最后一种情况下 - 您还需要更改您的电话

Finally in that last case - you would need to also change your calls from

var myValue = MyMethod();

var myValue = await MyMethod();

等等.使用 async 关键字标记所有调用等待其他方法的方法.

etc. marking all methods that make calls that await other methods with the async keyword.

这篇关于从 Windows 应用商店应用程序在我的图片中创建子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:10