Adding files to WP7 isolated storage from Visual Studio? - windows-phone-7

I'm working on an Windows Phone 7 app where I'm going to show ATM's nere your location with bing maps.
I have an xml-file with addresses and gps coordinates. But how do I add this file to my program from visual studio? If I set BuildAction to Content and Copy to output directory to Copy always. The file still isn't in IsolatedStorage. Do I have to build a mechanism to download the information from the web? Or is there another way?

Files listed as content in the Visual Studio project are copied to the generated XAP file (which is analogous to a ZIP file). They are not copied to isolated storage.
In the case of an XML file, you can call XmlReader.Create with the path to the file as argument, as follows:
using (XmlReader reader = XmlReader.Create("path/to/file.xml"))
{
// read XML file here
}
Or you can also call Application.GetResourceStream and use the Stream property of the returned StreamResourceInfo object:
StreamResourceInfo sri = Application.GetResourceStream(
new Uri("path/to/file.xml", UriKind.Relative));
// read XML file here from sri.Stream, e.g. using a StreamReader object

You cannot directly pass files to the isolated storage at design time. Only when the application is running.
I'd still recommend passing the file to the application through a web service. Mainly because if eventually you will need to change the contents of the XML, you will need to update the application.
What I would do is simply create a WCF service that will return serialized data (or the existing XML) via a simple HTTP request.

The "Mango" SDK ships with the ISETool that can take and restore snapshots of an application's isolated storage to/from a local directory:
# Copy data from IS to directory
ISETool.exe ts xd <PRODUCT-ID> "C:\TempDirectory\IsolatedStore"
# Copy data from IS to directory
ISETool.exe rs xd <PRODUCT-ID> "C:\TempDirectory\IsolatedStore"
If you don't want to overwrite the entire IS, the tool supports an option (device-folder) for specifying a sub-directory to backup/restore.

Related

How to return an image file (Byte[]) as a compressed file with Spring API?

I'm the company's file server
Get the file as byte[] through the image path and authentication key.
(This server is not accessible to me.)
What I want to do is, when the user downloads the selected files, I want to compress these files and provide them as a compressed file.
Since the company's file server does not have a download API for multiple files, I think I need to request as many APIs as the number of file lists with a for statement in my service API.
In other words, it seems that we need to take a List<Byte[]> and compress this list.
Is there something wrong with my method?
And can I pass the result as json after compression? (I confirmed that the image file is passed as json.)

Xamarin Essentials FileSystem can you save async

Looking into Xamarin essentials and wondering what the purpose of FileSystem is.
I was looking for something that would load and save a file for me async out of the box.
It looks to me and may be I am not understanding the usage that the only thing that it gives you is a location where to save and load the file and there is no functionality to actually save it for you eg "Old PCLStorage"
is this correct?
All Xamarin Essentials File System Helpers are doing is providing access to two different directories within your app, CacheDirectory and AppDataDirectory and access to the read-only pre-bundled files within application so you do not have to write platform-based code for these locations and do your own DI (or use Forms' DI) to access them...
Once you have the string-based directory location, then you use the normal .Net(Std) file and directory I/O routines. Create/delete subdirectories, create/read/write/delete a file using the async (or not) functions from the .Net(Std) framework or a third-party framework/package. Your choice...
CacheDirectory
The cache directory is a read/write location and it implements access to the "native" platform cache location. On Android this is the Cache
var cacheDir = FileSystem.CacheDirectory;
AppDataDirectory
The app data directory is the "default" location for where regular files should be stored.
As the docs state:
any files that are not user data file
FYI: This is not the place to be used for Sqlite databases and such if you are implementing/complying with platform dependent norms... Why Essentials did not include a database location is unknown to me when platforms like iOS and Android have APIs for them and formally documented locations... ;-/
Application bundled files (read-only)
OpenAppPackageFileAsync provides access (via a Stream) to read-only bundled files in your application (AndroidAssets, BundleResource, etc..)
using (var stream = await FileSystem.OpenAppPackageFileAsync("sushiLogo.png"))
{
using (var reader = new StreamReader(stream))
{
var fileContents = await reader.ReadToEndAsync();
}
}

Getting file inside PCL project always returning null

I am trying to get file which is added in PCL project usin PCLStorgae as below:
IFile file = await PCLStorage.FileSystem.Current.GetFileFromPathAsync("ProjectName.Data.AuthRequest.json");
Above is always returning null. BuildAction is set to Embedded Resource. It is possible to get file inside PCL, but what am I doing wrong here.
Update
Following code working fine without using PCLStorage:
var assem = typeof(Class).GetTypeInfo().Assembly;
Stream stream = assem.GetManifestResourceStream(string.Format("ProjectName.CustomFolder.FileName"));
using (var reader = new System.IO.StreamReader(stream))
{
text = reader.ReadToEnd();
}
Not sure why its returning null with PCLStorage.
PCLStorage is an abstraction over the file system differences of the various native platforms (iOS, Android, Windows etc).
Maybe you found the name of the library misleading? The "PCL" in "PCLStorage" means, it allows you to access the platform specific file systems from within your shared code (PCL). It's not about accessing files that are embedded into a PCL as a resource.
As you already figured out correctly, GetManifestResourceStream() is the correct way to go for embedded resources.

Download large file from Skydrive to Windows Phone 7

Am having some trouble with the SkyDrive download process and hoping you can help me.
Following the standard SkyDrive API & examples, I've set up a page that browses the SkyDrive folder structure, lets User click on a file, prompt to download, and it all works correctly.
Where I'm having trouble is when the file downloaded is large, I get the OutOfMemoryException thrown at around the 100Mb mark.
Dennis speaks on this problem here http://dotnet.dzone.com/articles/2-things-you-should-consider but it relates to a direct URL download, not via the SkyDrive architecture.
I've tried extracting the URL from SkyDrive and doing the direct download that way but haven't had any success.
Here is the code I'm using - the "item" object is of type SkyDriveItem, having iterated through a folders content and selected this file.
LiveConnectClient downloadClient = new LiveConnectClient(App.Session);
try
{
downloadClient.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(downloadClient_DownloadCompleted);
downloadClient.DownloadProgressChanged += new EventHandler<LiveDownloadProgressChangedEventArgs>(downloadClient_DownloadProgressChanged);
downloadClient.DownloadAsync(item.ID + "/content", item);
This will work fine when the file isn't too large, but as mentioned, select a big file (>100Mb) and it dies with the OutOfMemory exception.
Any pointers?
Thanks in advance
Resolved - While I was never able to use the downloadClient.DownloadAsync() method to download large files, playing with the downloadClient.getAsync() and using the Pre-Authenticated URL via a regular Stream downloader does the trick.

Is Isolated Storage Always Necessary?

I see alot of examples on how to write data from an app to a file then put it in isolated storage. I do not want to write any data to my xml file, I just simply want to save it into isolated storage then query it later.
A few simple questions
Someone have code on how to put an existing xml file into isolated storage. Also since I am not writing to this file, do I need isolated storage still? Can I just add the xml to my project and use Linq to xml to open it query it and close it on a button click?
I wanna query the xml through my application in the background. I see alot of examples on serializing, do I need to do this? Can I just open the xml file and use linq to xml to query the data?
Can I just do this, set bbxml.xml to Content and forget about isolated storage and just do this?
using (XmlReader reader = XmlReader.Create("bbxml.xml"))
{
XDocument xml = XDocument.Load(reader);
//query xml....
}
Include the XML file in your project files in Visual Studio, then in the Properties window make sure Build Action is set to Content and Copy to Output Directory is set to Copy always or Copy if newer. This will include the file in the output XAP file.
To access this file in code use:
XDocument doc = XDocument.Load( "path/to/my/file.xml" );
Of course, it doesn't have to be XDocument, you can use any XML reader class similarly.

Resources