How to get file folder names in windows phone 8? - c#

I have some folders and inside folders there are some files.i want to get the names of the folder(by iterating) and want to iterate through them to read the files.How can i achieve this in windows phone?

This will give you the installed folder on wp8,
StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
To access the files you can read more here Accessing files in wp8

Related

Create Folders and file in side Universal Window App

I am programming on Universal Windows Platform and want to create a folder in the given path URL but without using ApplicationData.Current.LocalFolder because it returns the path C: but the given path varies. Please advise.
We can not create a folder and a file from an arbitrary location on disk in a UWP App.
Apps can access certain file system locations by default. Apps can also access additional locations through the file picker, or by declaring capabilities.
For more info, please refer the File access permissions.
If you want to create a folder and a file to the Music, Pictures, and Videos libraries, we can declare capabilities in the app manifest (see App capability declarations). For more info, please refer Files and folders in the Music, Pictures, and Videos libraries.
We can also use the User’s Downloads folder. By default, your app can only access files and folders in the user's Downloads folder that your app created.
For the other Folders and files, we can call a file picker to let the user pick files and folders for the app to access (see Open files and folders with a picker).

How to get file shared assets in Win 8.1 universal app?

I have universal app and shared assets in it. These are pictures I use both in the mobile and in the desktop app. But, obviously installation folder is not accessible in code-behind. Is there way how to achieve that or I have to add pictures to both platform-wise projects?
But, obviously installation folder is not accessible in code-behind.
No, it is accessible.
Is there way how to achieve that or I have to add pictures to both platform-wise projects?
We can use Package.InstalledLocation to access the folders or files in the installed location for example like this:
var assetsfolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
And we don't need to add pictures to both platform projects. You can create a folder for example named "ShareAssets" in the [ProjectName].Shared like this:
And I put a image under this folder, so will both the windows 8.1 project and windows phone 8.1 project be able to access this folder:
<Image Source="ShareAssets/miao4.jpg" />
As the method I provided, we can also access this folder in the code behind from both platform:
var shareassetsfolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("ShareAssets");

How to get size in bytes of a StorageFolder on Windows Phone 8.1 (Universal App)

Is there a better way on Windows Phone 8.1 XAML/Universal App how to get total size of all files including nested files in a specific StorageFolder than recursively traversing all folders and counting manually size of all files?
Solution that works on Windows 8.1 (tablets/PC) is using CommonFileQuery that returns all nested files within specific folder.
StorageFileQueryResult filesQuery = downloads.CreateFileQuery(CommonFileQuery.OrderByName);
IReadOnlyList<StorageFile> files = await filesQuery.GetFilesAsync();
then you can Sum the size of all files easily. Unfortunately there is no working Query method on Windows Phone 8.1 that works in any folder and return deep list of files of a folder.
Update, just tested on Lumia 520 and getting size of a folder with 4 subfolders, each with single file using this method takes 1150 ms, that's just too much!

saving file in Assets folder in Windows 8 App

I am developing an App for Windows Store.
I have to save a recorded media as "file1.mp3" into the Assets folder without opening the save file prompt. I used the following code
StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFileAsync(#"Assets\file1.mp3",Windows.Storage.CreationCollisionOption.ReplaceExisting);
However the system returns an "access denied" error. The file has to be saved in the Assets directory only and I do not want to use FileSavePicker. Please Help.
Thanks
Your package folder is read-only. Use your app data folders from Windows.Storage.ApplicationData.Current instead, wherein you'll find a LocalFolder and TemporaryFolder (also RoamingFolder but an mp3 would exceed the 100KB roaming limit). Then you can use either folder's CreateFileAsync.

Windows RT 8 - view files in application storage

So I'm writing an xml file to the local Storagefolder
using Windows.Storage;
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
And i would like to view this file in the Windows Explorer for debug purposes.
Is there any way?
It is located under
C:\Users\*Username*\AppData\Local\Packages\*application specific letters and numbers*\LocalState
You can easily determine the path by exploring the Path property of your localFolder object.
All your application data are in \Users\\Appdata\Local\Packages.
Choose your application, and go in the LocalState folder.

Categories

Resources