Exemplo n.º 1
0
        public static bool DownloadFile(string url, string filename, bool forceDownload)
        {
            if (File.Exists(filename))
            {
                if (!forceDownload)
                {
                    return(true);
                }
                File.Delete(filename);
            }
            Uri uri = new Uri(url);

            if (uri.IsFile)
            {
                string source = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);
                File.Copy(source, filename);
                return(true);
            }
            complete = false;
            canceled = false;
            client.DownloadFileAsync(uri, filename);

            System.Threading.Thread.Sleep(250);
            if (!complete)
            {
                dialog = new FileDownload();
                dialog.ShowDialog();
            }
            if (canceled)
            {
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
            }


            return(!canceled);
        }
        public static bool DownloadFile(string url, string filename, bool forceDownload)
        {
            if (File.Exists(filename))
            {
                if (!forceDownload)
                {
                    return true;
                }
                File.Delete(filename);
            }
            Uri uri = new Uri(url);
            if (uri.IsFile)
            {
                string source = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);
                File.Copy(source, filename);
                return true;
            }
            complete = false;
            canceled = false;
            client.DownloadFileAsync( uri, filename);

            System.Threading.Thread.Sleep(250);
            if (!complete)
            {

                dialog = new FileDownload();
                dialog.ShowDialog();
            }
            if (canceled)
            {
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
            }

            return !canceled;
        }