I am working in WinRT, and I am kind of stuck:
I am writing a music player with a media library capability. I keep information about the music (such as artists etc) in a SQLite database. I wanted to let the user keep his music anywhere he wants to, instead of the windows way, where it all has to be in the 'Music' library.
Users can add the music inside folders using a folder picker. The problem I have is this: how can I access these files later, e.g after the application restarts?
Keeping the path doesn't work, since I always get "Access Denied" errors. The only time I can access the files is using the StorageFile objects I get from browsing the folder.
How can I solve this issue?
As in the comments already given, the Windows.Storage.AccessCache (http://msdn.microsoft.com/en-us/library/windows/apps/br230566.aspx) is the API you need to use for this. However, instead of saving access to each individual StorageFile, use the folder picker and save permissions for the StorageFolder object instead (the API works for both). It's unlikely that you'll hit the 1000 item limit for folders.
Windows Runtime apps are sandboxed. If you want to access arbitrary folder locations, you have to use the file picker.
to access files in future
string key = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(storageFile);
//save this key for access file later
//Access file from saved key
StorageFile file = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(key);
if you have too much file you can add StorageFolder of files
string key = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(storageFolder);
StorageFolder folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(key);
then get StorageFiles from the parent StorageFolder
StorageFile childFile = await folder.GetFileAsync("filename");
Related
I am using this code to check if the client runs from DMG /Volume, and show an alert and quit.
private void IsRunningFromDMG()
{
var currentPath = NSBundle.MainBundle.BundlePath;
if (currentPath.StartsWith("/Volumes", StringComparison.Ordinal))
{
using (var alert = new NSAlert
{
MessageText = "Warning",
InformativeText = "You cannot run this application from DMG, drag move to the " +
"\"/Applications\" folder"
})
{
alert.RunModal();
NSApplication.SharedApplication.Terminate(null);
}
}
}
This is fine if the system language is set to English. I doubt if the /Volumes reacts to localization in that case how to do it?
There should be a system defined constant that would take care of it?
If it is, please help me to know what is it.
Filesystem paths do not change based on localization, they are localized for "display" though (i.e. Pictures, Music, etc... would be localized in Finder for display to the user but the filesystem path is still /User/xxx/Pictures, etc...)
Localized names. The system provides localized names for many system directories, such as Applications, Library, Music, Movies. An app may similarly provide localized names for itself and for any directories it creates.
Display names do not affect the actual name of the file in the file system. Code that accesses a file or directory programmatically must specify the item’s actual name when opening or manipulating the item using the file system interfaces. The only time your app should ever use display names is when displaying the name of a file or directory to the user. You can get the display name for any file or directory using the displayNameAtPath: method of NSFileManager.
i.e.
var urls = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.ApplicationsDirectory, NSSearchPathDomain.System);
var applicationDisplayName = NSFileManager.DefaultManager.DisplayName(urls[0].AbsoluteString);
Note: You should use NSSearchPathDirectory.AllApplicationsDirectory within the NSSearchPathDomain.All domain to obtain a valid list of "Application" urls where your application might/should be located at, instead of hard coding it to the "System" application location.
I tried moving uploaded file through browse action in socialengine from /public/user/ to /Files/SE/ by using
1.
$fileobj = new Zend_Cloud_StorageService_Adapter_FileSystem();
$fileobj->moveItem($sourcePath, $destinationpath);
move_uploaded_file($sourcePath, $destinationpath);
Both of these couldn't move the file. I have checked the paths too they are perfect and works with other frameworks
You should use API of Storage module which will allow you to create temporary files (when you need to resize images or convert videos) and then place them into public storage. This files will be tracked in engine4_storage_files table.
I got it worked by using createSystemFile() function under storage > Model > DbTable > Files.php
I created a function similar to this and gave parent_type as the folder which I wanted to move in the files.
I have got a app with the getItemsAsync()-method returning a file-object for a picture chosen by the user with a file picker. Now I would like to get the folder-object of the folder which contains the image to make the user able to switch between the pictures in that folder without using the filepicker again.
The path is available upon return from the file picker. See:
Docs for StorageFile
You can in turn then call
Windows.Storage.StorageFolder.getFolderFromPathAsync(path)
.done( /* Your success and error handlers */ );
to get you the StorageFolder from that path.
Docs for GetFolderFromPathAsync()
if the app likely want to 'access' any file in the select folder, using FolderPicker is probably right. otherwise, the app will likely not have access to all files in the folder.
I'm new to Windows 8 app development. I'm trying to port a old application I wrote in .NET. This application uses base data which is stored as four XML files that were added to the project as "Ressource" and deserializes them using the System.Xml.Serialization.XmlSerializer.
What would be the best way to ship data like this with an Windows 8 Store App? Just put them in the Assets Folder?
What is the best way to load and bind data like this in an Windows 8 app?
I'm grateful for everything you can give me, a direct answer, helpful links or an video on data loading and binding in Windows 8 ...
You can use resources in store app, here is the example :
public static string GetXmlContentsFromResource(Assembly asm, string dataName)
{
string contents = "";
Stream stream = asm.GetManifestResourceStream(asm.GetName().Name + "." + dataName);
using (StreamReader reader = new StreamReader(stream))
{
contents = reader.ReadToEnd();
}
return contents;
}
You should add XML files to solution and mark it as "Embedded Resource", and if you put XML files in subdirectory, for example if folder is named Data and xml file is Data1.xml then you should send parameter dataName to above method like this "data.Data1.xml".
For Data Binding best aproach is to deserialize that XML to object or list of objects that reflects XML contents.
What would be the best way to ship data like this with an Windows 8 Store App? Just put them in the Assets Folder?
Yes, put them in your assets folder. Be sure to set the build properties to "Content" + "Copy To Output". Once you have done this, you can access them from your app using the following url: ms-appx:///Assets/myxmlfile.xml
For example:
StorageFile xmlFile = await StorageFile.GetFileFromApplicationUriAsync
(new Uri("ms-appx:///Assets/myxmlfile.xml"));
The above gives you a file object that you can use to read your file. Obviously, since you are reading from the Assets folder, your file will be read-only.
What is the best way to load and bind data like this in an Windows 8 app?
As to data binding, that is probably a bit too large to cover in one answer. You might want to take a look at this Windows 8 Data Binding Sample.
I'm trying to take and save a photo using a windows surface device.
I'm using the code below to take a photo and this work but I'd like to automatically create a directory on the device's local drive and save this photo there without any dialog prompts.
So the code I use to capture to photo is as follows:
CameraCaptureUI camera = new CameraCaptureUI();
StorageFile file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (file!=null)
{
using (IRandomAccessStream ras=await file.OpenAsync(FileAccessMode.Read))
{
BitmapImage source = new BitmapImage();
source.SetSource(ras);
imageBuildingPhoto.Source = source; // this is just an image control.
}
}
So after this I'd like to automatically save the photo to a new directory. e.g.
My Pictures\NewDirectory\Photo1.jpg
Anybody got any idea how I can do this?
This is a windows store application written using C#4.5 and XAML.
Thanks in advance
Use the CopyAsync method on the StorageFile object you get back (file). You can specify a directory and file name. If you need to create your own directory structure, you will need to enable access to the appropriate library in the Package Manifest then create it in code. You will then use the StorageFolder class and its CreateFolderAsync method to create folders.
http://aka.ms/30Days has some great resources for learning about scenarios like this. Might be worth checking out.
Your code will need to look to see if that folder exists and create it if it does not. Your app will need to declare the capability to access the user's Photos library in the app manifest, too.
To take a picture, your code is correct. I have a walkthrough in case you want to verify it against some other code: http://blog.jerrynixon.com/2012/10/walkthrough-capturing-photos-in-your.html
To interact with the file system, this can be tricky, but I have a longer write up on that if you want to reference it: http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html
The answer to your question is, yes you can. I have done it in my own apps. Now, it's just a matter of you implementing it in yours. You will find it to be pretty easy.