i need to save a xml file from a server.. i found a code to make the download but i don’t understand how to save the file into memory.. How can i do that? I search in google and i have this:
public MainPage()
{
InitializeComponent();
WebClient downloader = new WebClient();
Uri xmlUri = new Uri("http://dl.dropbox.com/13258/file.xml", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Downloaded);
downloader.DownloadStringAsync(xmlUri);
}
void Downloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the xml-file");
}
else
{
MessageBox.Show("Download succeed");
}
}
I want to make the download and save it into the memory.
The code you have will download a file from a server. In Downloaded() you will need to add some code to save the file you have just downloaded.
On WP7 You save files to isolated storage. This is a application specific file system you can use to save any files you want your application to use. The following link describes how isolated storage can be used:
http://www.windowsphonegeek.com/tips/all-about-wp7-isolated-storage-read-and-save-text-files
In your case add this to the Else in Downloaded()
Take care with the FileMode Enumeration Type, the example above uses OpenOrCreate which will open an existing or Create a new file, i.e. overwrite any existing file with that name in the root folder of isolated storage. Details on this enumeration are here:
http://msdn.microsoft.com/en-us/library/system.io.filemode.aspx