How to Save File to Isolated Storage in Windows Phone 8?

Published on September 15, 2013 by abundantcode

Filed under Windows Phone

Last modified September 15, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 7240 times

There are times when you want to copy the files to isolated storage in your Windows Phone 8 App which you can do it easily using C#.

Below is a sample code snippet that demonstrates the copying of file to isolated storage in Windows Phone 8 using C#?

How to Save File to Isolated Storage in Windows Phone 8?

private static void SaveFileToIsolatedStorage(Uri fileUri,string _fileName)

{

var AppIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();

var FileName = AppIsolatedStorage.CreateFile(_fileName);

var FileData = Application.GetResourceStream(fileUri);

byte[] bytes = new byte[4096];

int Count;

while ((Count = FileData.Stream.Read(bytes, 0, 4096)) > 0)

{

FileName.Write(bytes, 0, Count);

}

FileName.Close();

}

Calling the function

Uri songUri = new Uri("test.mp3", UriKind.RelativeOrAbsolute);

SaveFileToIsolatedStorage(songUri, "test.mp3");

Note: make sure that test.mp3’s build action is set to “Content” and the “Copy to Output Directory” is set to “Copy Always”.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

3 Comments

  1. How to Copy a Song to Windows Phone Music Hub/Library using C#? | Abundant Code
    September 15, 2013 - 1:37 pm

  2. Andrés García

    Thank you! from Argentina. I was using IsoStoreSpy in win 8 but in win 10 its not working. This helped me a lot. Thanks again.

    April 17, 2016 - 2:32 pm – Reply

    • AbundantCode

      Thanks for the feedback 🙂

      April 19, 2016 - 2:38 pm – Reply

Leave a Comment


x

You might be Interested in these Posts

How to delete user account from command line in Windows 10 ?

You can delete a user account from command line in Windows 10 using the net user command and specify...

How to add new user account from command line in Windows 10 ?

You can add a new user account in Windows 10 using command prompt using the net user command and pas...

How to open display settings from command line in Windows 10 ?

The display properties can be found in the settings app in Windows 10 which lets the users to config...