1

In referencing http://tizianocacioppolini.blogspot.com/2014/01/windows-phone-8-folders-and-files.html#.U6YbkfhOXIU I am trying to put together a sample where I can gather a photo using the PhotoChooserTask and Save/Retrieve this photo using AppicationData. The ultimate goal is to save the image in a folder using the new ApplicationData method, and if the folder already exists remove and replace it. I am unsure of how to set this up properly

MainPage.xaml.cs

protected override void OnNavigatedTo(NavigationEventArgs e)
{
        base.OnNavigatedTo(e);

        //If an image exists in the folder, set the image to the page background using TombstoningHelper.cs Retrieve method

}

private void Browse_Click(object sender, RoutedEventArgs e)
    {
        photoChooserTask.Show();
    }

    void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            // get the file stream and file name
            Stream photoStream = e.ChosenPhoto;
            string fileName = Path.GetFileName(e.OriginalFileName);

            //Save the Image to storage using TombstoningHelper.cs
        }
    }

TombstoningHelper.cs

public async Task StorePhoto(Stream photoStream, string fileName)
    {
        StorageFolder folder;

        //Check if folder exists

        //If folder exists, delete it


        // persist data into isolated storage
        StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

        using (Stream current = await file.OpenStreamForWriteAsync())
        {
            await photoStream.CopyToAsync(current);
        }
    }

    public async Task<BitmapImage> RetrievePhoto(string fileName)
    {
        StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
        Stream imageStream = await file.OpenStreamForReadAsync();

        //Check if file exists

        // display the file as image
        BitmapImage bi = new BitmapImage();
        bi.SetSource(imageStream);

        return bi;
    }
Matthew
  • 3,976
  • 15
  • 66
  • 130
  • If you dont find an answer for this then check out the free dll I wrote that controls the Isolated Storage for you. It's called EZ_iso version 4.0. I have the dll, source and documentation here http://anthonyrussell.info/postpage.php?name=2 The documentation example for saving an image is the exact thing you are trying to do. – DotNetRussell Jun 24 '14 at 17:21

0 Answers0