I'm creating a Windows 8 application and i need to store some Data about the application in a text file inside the Application , i found this useful tutorial http://msdn.microsoft.com/en-us/library/windows/apps/hh464978.aspx but it use a know folder to store the file in my case i want to store it inside the application
i've found the answer , you can get The location using
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
and then using it in Writing and Reading From and to Files
This link is useful
Related
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'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.
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");
I want to implement the Share source contract in my WinRT C# Metro app (Windows Release Preview). My app is storing arbitrary files. Not in the filesystem, but instead I get the data over a WCF service as byte[]. Now I want to share such "files" in my app.
The only possibility I've seen with a standard data format is using the SetStorageItems() method on the DataPackage. Thus I'm facing the challenge to convert the data from my byte array to a StorageFile, which can be shared. I found the StorageFile.CreateStreamedFileAsync() method and wanted to use it in this way:
// filename: string
// fileContent: byte[]
// ... setting DataPackage title and description ...
DataRequestDeferral deferral = args.Request.GetDeferral();
var file = await Windows.Storage.StorageFile.CreateStreamedFileAsync(filename,
async stream => await stream.WriteAsync(fileContent.AsBuffer()), null);
args.Request.Data.SetStorageItems(new List<IStorageItem> { file });
deferral.Complete();
It compiles fine, but it doesn't work as expected. I've tried the sharing with the standard Mail app. The Mail share view opens and I can create a new mail. The file is shown without thumbnail (as expected), but the e-mail can't be sent. It's showing the sending progress for several minutes and then an error occurs: "Couldn't share {filename} with Mail.". The share charm shows "Something went wrong" and "[...] Mail can't share right now. Try again later.".
It works perfectly when I load the StorageFile from the file system: the mail opens and is sent within seconds, no problems here. So either I'm using CreateStreamedFileAsync() wrong or there's a bug in this method, what do you think?
In the callback passed into CreateStreamedFileAsync, you need to actually dispose of the object - that signals to the OS that you are done.
Wrote a complete example here
The Mail app is not a target for sharing files. From http://blogs.msdn.com/b/b8/archive/2012/06/14/building-the-mail-app.aspx: "Mail supports sharing text, links, and pictures."
Remember that there are 2 parts of the Share contract: Share sources and Share targets. As you know, there are many different data formats that can be shared between them, like text, pictures, URIs, and files. The full list of the different data formats that are supported is at http://msdn.microsoft.com/en-us/library/windows/apps/hh771179.aspx.
I recommend that you use the Share Target Sample app to test that your file is being shared properly - share to this and it will display everything that is being shared from your app as a source (and it does accept files for sharing). You can download it from http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782. You can also use the Share Source Sample app as an example and leverage code from this app; you can download it from http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Source-App-d9bffd84.
Hope that helps!
Ok, perhaps the preview version of the Mail app doesn't handle the sharing target contract correctly. Using the SDK sample app "Sharing Content Target App" from http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782, sharing a StorageItem created in memory with the StorageFile.CreateStreamedFileAsync() method posted above works fine.
Thus, that's the way you should go when you want to share in-memory byte[] arrays. For testing, make sure that the share target app doesn't run in Visual Studio when you want to share data from another app with it. Then the sharing sidebar mysteriously will disappear automatically...