There are multiple methods to download files in WP7, such as using httpwebrequest, WebClient, or even background processes to download files. For files such as images supported by WP, you can also bind a data source to the control for automatic download.
The method of using WebClient can refer to this better example: http://www.cnblogs.com/linzheng/archive/2011/11/03/2234971.html
Example of using background processes to upload and download files: http://www.cnblogs.com/webabcd/archive/2012/07/16/2592989.html
For images, You can bind a remote URI to automatically download the image and display it after the system is complete. For example:
<Image Source="http://xxx.com/xxx/remoteImage.png" Stretch="None" />
If you want to display a default image before the image download is complete, and then update the image after the download is complete, you can listen to this to complete the download. For how to implement it, refer to the following code:
Bitmapimage bitmap = new bitmapimage (); bitmap. createoptions = bitmapcreateoptions. none; // when the image is downloaded and decoded successfully, the imageopened bitmap is triggered. imageopened + = (S, e) =>{// display the image in the control userheadimage. The control has defined userheadimage in XAML. source = s as bitmapimage;}; // URI is the remote file address bitmap. urisource = new uri (URI );
The last thing worth thinking about is that the client may implement the file caching mechanism and want to know if the network file has been changed. It is necessary to download the file only when the client has been changed, otherwise, the traffic waste caused by repeated downloads is avoided. In a solution, a simple request is sent before the file is downloaded, requesting the server to send back the last modification time and other information of the file. At the same time, the client will save the last update time of the file, and then compare the two times. If the server time is newer, download the file; otherwise, the locally cached file will continue to be used. This imitates the browser's page loading technology.
The following describes how to send a WebClient request and obtain the last modification time of a file in the header information returned by the server:
WebClient request = new WebClient(); request.OpenReadAsync(new Uri(url)); request.OpenReadCompleted += (s, e) => { string lastModifiedDate = request.ResponseHeaders["Last-Modified"]; };