简体   繁体   中英

Port from winForms to Windows phone 8.0 C#

can someone help me out by porting/translating this piece of c# code wrote in winForms to Windows phone 8.0 ? Im really struggling with it and i cant make it work i probably read every single documentation that i could get my hands on but i just cant make it work. I know that stackover flow is not place where people write code for you but im hopeless.. any help is appreciated Im trying to load some info about my app from a text document and image im loading those things in array of images and array of strings. Here's the code :

private static string[] _folderPaths = Directory.GetDirectories(@"Folders");
    private string[] _imagePaths;
    private List<string> _questionsPaths = new List<string>();
    private List<string> _correctAnswersPaths = new List<string>();
    private List<string> _allAnswersPaths = new List<string>();

for (int i = 0; i < _folderPaths.Length; i++)
        {
            var _tempLocations = Directory.GetFiles(_folderPaths[i], (i + 1).ToString() + "*.txt*");
            _imagePaths = Directory.GetFiles(_folderPaths[i], "*.png", SearchOption.TopDirectoryOnly);
            foreach (string item in _tempLocations)
            {
                if (item == "Folders\\" + (i + 1).ToString() + "\\" + (i + 1).ToString() + ".txt")
                {
                    _questionsPaths.Add(item);
                }
                if (item == "Folders\\" + (i + 1).ToString() + "\\" + (i + 1).ToString() + "answer" + ".txt")
                {
                    _correctAnswersPaths.Add(item);
                }
                if (item == "Folders\\" + (i + 1).ToString() + "\\" + (i + 1).ToString() + "answers" + ".txt")
                {
                    _allAnswersPaths.Add(item);
                }
            }
        }

The corresponding types used in Windows Phones are (not precise mapping, of course):

Directory -> StorageFolder
Directory.GetDirectories -> StorageFolder.GetFoldersAsync
Directory.GetFiles -> StorageFolder.GetFilesAsync

So the translated code would be something like this (you need to be familiar with the new await-async keywords too)

using Windows.Storage; 

var folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Folders"); 
var subFolders = await folder.GetFoldersAsync();
foreach (StorageFolder subFolder in subFolders)
{
    var tempFiles = await subFolder.GetFilesAsync(...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM