I am trying to save several image files from my XAP into the isolated storage using the following code. I plan to save around 100 files. The problem is the line
sri = Application.GetResourceStream(uri)
returns null half way. Is there a limit as to the number of files the emulator can save? Or may be I’m missing something..
private static void SaveImageFileToIsoStore()
{
string[] files = AllFilesInImagesCatFolder();
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoStore.FileExists(files[0]))
{
foreach (string f in files)
{
IsolatedStorageFileStream fileStream = isoStore.CreateFile(f);
StreamResourceInfo sri = null;
Uri uri = new Uri("Images/cat/" + f, UriKind.Relative);
Debug.WriteLine(f);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
fileStream.Close();
fileStream.Dispose();
}
}
}
}
I’ve figured it out. Two of the files have a png and jpeg extensions. The code is expecting jpg extension only so it returns null when it encounters those extensions.