net 把指定 URI 的资源下载到本地

 

            DirectoryInfo dir = new DirectoryInfo(AppContext.BaseDirectory);
            var path = dir.FullName + @"tempFile\";
            var filePath = path + Guid.NewGuid() + fileName;
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            using (WebClient client = new WebClient())
            {
               // address:从中下载数据的 URI,www.xxxx.com/xx.jpg
               // filePath:从中下载数据的 URI,C:\\tempFile\\xx.jpg
                client.DownloadFile(address, filePath);
            }

 

posted @ 2019-04-12 11:29  Robot-Blog  阅读(489)  评论(0编辑  收藏  举报