StorageFolder GetFolderFromPathAsync Windows Phone 8

时间:2014-03-13 14:47:53

标签: windows-phone-8

你好我有这个代码

private async Task SaveImageToIsolatedStorage(Stream stream)
        {

            StorageFolder Datafolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Data");
            StorageFolder subfolder1 = await Datafolder.GetFolderAsync("subfolder1");
            StorageFolder subfolder2 = await subfolder1 .GetFolderAsync("subfolder2");

            StorageFile file = await subfolder2.CreateFileAsync("test.jpg", CreationCollisionOption.ReplaceExisting);
            using (Stream current = await file.OpenStreamForWriteAsync())
            {
                await stream.CopyToAsync(current);
            }

        }

如果我直接使用StorageFolder.GetFolderFromPathAsync(" Data \ subfolder1 \ subfolder2")收到错误

{System.IO.FileNotFoundException:系统找不到指定的文件

怎么样?

2 个答案:

答案 0 :(得分:1)

根据msdn上的帖子,你需要使用双斜杠:

StorageFolder.GetFolderFromPathAsync("Data\\subfolder1\\subfolder2")

http://social.msdn.microsoft.com/Forums/windowsapps/en-US/2587b868-4f78-47e7-bae1-314b6eb5d9f3/how-do-i-access-a-file-that-is-nested-inside-other-folders?forum=winappswithhtml5

答案 1 :(得分:0)

好的,可以使用这段代码

StorageFolder folder= await ApplicationData.Current.LocalFolder.GetFolderAsync("Data\\subfolder\\subfolder1");