/// <summary>
 /// Asynchronously downloads file from the specified url to the specified path
 /// </summary>
 /// <param name="url"></param>
 /// <param name="filePath"></param>
 /// <param name="callback">A <see cref="DownloadImageCompletedCallback"/> to be invoked when the request is completed</param>
 /// <param name="progressCallback"></param>
 /// <returns></returns>
 public object DownloadFileAsync(string url, string filePath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback)
 {
     string urlValidationError;
     if (!IsValidURL(url, out urlValidationError))
         throw new ArgumentException(urlValidationError);
     FileRequestAsyncState state = new FileRequestAsyncState(filePath, callback, progressCallback, DownloadFileAsyncCompleted);
     HttpWebServiceRequest request = GetRequest();
     request.GetResponseAsync(url, new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None), IMAGE_ACCEPT, null, state);
     return request;
 }
        /// <summary>
        /// Asynchronously downloads file from the specified url to the specified path
        /// </summary>
        /// <param name="url"></param>
        /// <param name="filePath"></param>
        /// <param name="callback">A <see cref="DownloadImageCompletedCallback"/> to be invoked when the request is completed</param>
        /// <param name="progressCallback"></param>
        /// <returns></returns>
        public object DownloadFileAsync(string url, string filePath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback)
        {
            string urlValidationError;

            if (!IsValidURL(url, out urlValidationError))
            {
                throw new ArgumentException(urlValidationError);
            }
            FileRequestAsyncState state   = new FileRequestAsyncState(filePath, callback, progressCallback, DownloadFileAsyncCompleted);
            HttpWebServiceRequest request = GetRequest();

            request.GetResponseAsync(url, new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None), IMAGE_ACCEPT, null, state);
            return(request);
        }
 public FileRequestAsyncState(string filepath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback, WebRequestAsyncCallback webRequestCallback)
     : base(webRequestCallback, progressCallback)
 {
     _filePath = filepath;
     _downloadFileCompleted = callback;
 }
 public FileRequestAsyncState(string filepath, DownloadFileCompletedCallback callback, DownloadProgressChangedCallback progressCallback, WebRequestAsyncCallback webRequestCallback)
     : base(webRequestCallback, progressCallback)
 {
     _filePath = filepath;
     _downloadFileCompleted = callback;
 }