1. DaveGx's Avatar
    See third post below:
    Last edited by DaveGx; 06-25-2014 at 07:19 PM.
    06-23-2014 07:23 PM
  2. astondg's Avatar
    I have some background images in my app that I retrieve from URLs and cache in isolated storage so maybe this will be helpful for you:
    private static async void image_ImageOpened(object sender, RoutedEventArgs e)
        var image = sender as BitmapImage;
        if (image == null) return;
        string fileName = GetFileNameFromPath(image.UriSource.AbsolutePath);
        var writableBitmap = new WriteableBitmap(image);
        var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(AppConstants.LOCALFOLDERNAME_BACKGROUND, CreationCollisionOption.OpenIfExists);
        var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
        using (var stream = await file.OpenStreamForWriteAsync())
            Extensions.SaveJpeg(writableBitmap, stream, image.PixelWidth, image.PixelHeight, 0, 100);
    private static string GetFileNameFromPath(string path)
        int lastSlashIndex = path.LastIndexOf('/');
        return HttpUtility.UrlDecode(path.Substring(lastSlashIndex + 1, path.Length - lastSlashIndex - 1));
    Btw: 'async void' is bad but I wanted to run this code in an event handler so I'm not sure there's a better way
    Last edited by astondg; 06-23-2014 at 10:02 PM.
    06-23-2014 09:40 PM
  3. DaveGx's Avatar
    I got some assistance and have got something partially working. There is one issue and one wish. First the issue. The way it works right now is. First time using app, user presses button. Sound downloads in background from url. Press button again, sound plays. However, if you press the same button again, I get an Operation not permitted on IsolatedStorageFileStream at this line: audioStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(data.SavePath, FileMode.Open);

    That tells me it goes through the code fine to download it with webclient. Then even plays it. But to play the same button sound again, it errors. However, if I dont press the same button again, and press another one, I can go back to the initial one and play it. Just never can play it twice in a row without the app crashing. Here is the relevant code:

    [CODE] private void LongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
    LongListSelector selector = sender as LongListSelector;

    // verifying our sender is actually a LongListSelector
    if (selector == null)

    SoundData data = selector.SelectedItem as SoundData;

    // verifying our sender is actually SoundData
    if (data == null)

    if (data.IsDownloaded)
    if (audioStream != null)


    audioStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(data.SavePath, FileMode.Open);

    // Apparently MediaElement doesn't like isostore:/



    WebClient client = new WebClient();
    client.OpenReadCompleted += (senderClient, args) =>
    using (IsolatedStorageFileStream fileStream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(data.SavePath))
    args.Result.Seek(0, SeekOrigin.Begin);
    client.OpenReadAsync(new Uri(data.FilePath));

    selector.SelectedItem = null;[/CODE]

    Another thing is it doesn't play the sound after downloading without pressing the button again. I was trying to get that to work right but couldnt. But obviously my main concern is the crashing.
    06-25-2014 06:49 PM
  4. 0vZ's Avatar
    Try step-by-step debuging and you'll see what line is raising exception and what exception would it be.
    06-30-2014 12:24 AM

Similar Threads

  1. Qi charging with case on (hybrid case)
    By Rawliglat x in forum Nokia Lumia 1520
    Replies: 11
    Last Post: 06-24-2014, 07:37 AM
  2. Microsoft targets Unity developers with game porting lab in August
    By WindowsCentral.com in forum Windows Central News Discussion
    Replies: 0
    Last Post: 06-23-2014, 05:30 PM
  3. Bluetooth pairing with new laptop.
    By jleebiker in forum Nokia Lumia 928
    Replies: 0
    Last Post: 06-23-2014, 11:41 AM
  4. Download Sleeve Music today and rock the beat with free premium upgrade
    By WindowsCentral.com in forum Windows Central News Discussion
    Replies: 0
    Last Post: 06-23-2014, 10:00 AM