Downloading a file from the Internet
When your application needs to present content in the offline mode, it is necessary to download data from the Internet and store them on the device. Of course, such content could consist of text, images, or even movies. However, how can you download images and movies, as well as save them in a device? You will learn it in this recipe.
As an example, you will create a page with the Download a photo button. After clicking on it, you will download a file from a given address and save locally. Of course, you will also handle a scenario when a user does not have an Internet connection or when a remote file does not exist.
Getting ready
To step through this recipe, you need only the automatically generated project.
How to do it...
To prepare an example that downloads a file from the Internet and saves it locally, perform the following steps:
Add a button to the page by modifying the content of the
MainPage.xaml
file, as follows:<Page (...)> ...