C08623583.fm Page 312 Monday, December 10, 2007 9:45 PM 312 Part II Solutions for Challenges in Mobile Application To help you put all these concepts together, the following code sample shows a method to perform a download and save the received data to the device file system. private void Download(Uri address, string localPath) { string filename = address.Segments[u.Segments.Length - 1]; WebRequest request = WebRequest.Create(u); //Perform the GET request. WebResponse response = request.GetResponse(); //Get stream containing received data. Stream s = response.GetResponseStream(); //Open filestream for the output file. FileStream fs = new FileStream(Path.Combine(localPath, filename), FileMode.Create, FileAccess.Write); //Copy until all data is read. byte[] buffer = new byte[1024]; int bytesRead = s.Read(buffer, 0, buffer.Length); while (bytesRead > 0) { fs.Write(buffer, 0, bytesRead); bytesRead = s.Read(buffer, 0, buffer.Length); } //Close both streams. fs.Close(); s.Close(); response.Close(); } You can use the WebRequest approach to download or upload content for your application, or even to