c# - What need I do to get this code to work in a Portable Class Library? -
i'm wondering if portable class library more restricted in functionality compact framework.
i'm trying port cf/windows ce app (runs on handheld device) xamarin solution target android, ios, windows phone, , perhaps other things.
one of problems run into, though, legacy code (which works under cf):
public static list<string> getxmlfiles(string filetype, string startingdir) { const string extension = ".xml"; string dirname = startingdir; // call so: getxmlfiles("abc", "\\"); <= think double-whack need windows ce device...am right? var filenames = new list<string>(); try { foreach (string f in directory.getfiles(dirname)) { string extension = path.getextension(f); if (extension != null) { string ext = extension.toupper(); string filenameonly = path.getfilenamewithoutextension(f); if (filenameonly != null && ((ext.equals(extension, stringcomparison.ordinalignorecase)) && (filenameonly.contains(filetype)))) { filenames.add(f); } } } foreach (string d in directory.getdirectories(dirname)) { filenames.addrange(getxmlfiles(filetype, d)); // brad rem's answer here: http://stackoverflow.com/questions/22186198/why-is-this-function-returning-nothing-although-there-is-a-match/22186351?noredirect=1#22186351 } } catch (exception ex) { messagebox.show(ex.message); } return filenames; }
...won't compile in xamarin/cpl solution. get, "the name 'directory' not exist in current context" , right-clicking word not afford "resolve" option.
is there way pcl recognize "directory" or must rewrite code? if latter, have suggestions on do/use in stead?
relatedly, there url show me [not] available in pcl and/or site show how of provided block of code "pcl-ready"?
update
the first image in this article illuminating. later on, talks "directory" not being available in pcl scenario.
update 2
i downloaded pclstorage package referenced daniel plaisted below allow me access file system within pcl project.
using sample code @ start of download page [http://pclstorage.codeplex.com/] starting point, i've gotten far:
public async task<list<string>> getxmlfiles(string filetype, string startingdir) { const string extension = ".xml"; ifolder rootfolder = filesystem.current.localstorage; ifolder folder = await rootfolder.getfolderasync(startingdir, creationcollisionoption.openifexists); //createfolderasync(startingdir, creationcollisionoption.openifexists); list<string> filenames = await folder.getfilesasync(extension); return filenames; }
...but "extension" arg getfilesasync() not right. this, "argument 1: cannot convert 'string' 'system.threading.cancellationtoken'"
so need *.xml files folder?
update 3
this compiles, i'm not @ sure it's right way it, besides fact gets all files folder, rather match "*.xml":
public async task<list<ifile>> getxmlfiles(string filetype, string startingdir) { const string extension = ".xml"; ifolder rootfolder = filesystem.current.localstorage; ifolder folder = await rootfolder.getfolderasync(startingdir, system.threading.cancellationtoken.none); ilist<pclstorage.ifile> filenames = await folder.getfilesasync(system.threading.cancellationtoken.none); return filenames.tolist(); }
windows phone applications not use file system of operating system , restricted using isolated storage persist , access files, namespace not provide additional functionality.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.io%28v=vs.105%29.aspx
Comments
Post a Comment