This function accepts the full URL of a JPG, png, bmp, pdf or any file out there that is exposed via http. It will then save the binary file to any local path that you want (that you have permissions to).

I used this particular function to retrieve a Sharepoint attachment file, so that I can display it on an iOS device using mono-touch.


private static bool DownloadImage (string url, string filename)

{

    System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create (url);
    webRequest.Timeout = (30000);
    webRequest.Credentials = new System.Net.NetworkCredential (Settings.Instance.UserName, Settings.Instance.Password, Settings.Instance.Domain);

    using (System.Net.HttpWebResponse webresponse = (System.Net.HttpWebResponse)webRequest.GetResponse()) {
        using(Stream sourcestream = webresponse.GetResponseStream()) {
            using(FileStream filestream = new FileStream(filename,FileMode.Create,FileAccess.ReadWrite))
            {

                int Length = 256;
                byte [] buffer = new byte[Length];
                int bytesRead = sourcestream.Read(buffer,0,Length);
                while( bytesRead > 0 )
                {
                    filestream.Write(buffer,0,bytesRead);
                    bytesRead = sourcestream.Read(buffer,0,Length);
                }
                filestream.Close();
            }
            sourcestream.Close ();
            webresponse.Close ();
        }
    }
}