欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-06-10 09:10:51
DirectoryInfo dir = new DirectoryInfo(AppContext.BaseDirectory); var path = dir.FullName + @"tempFile\"; var filePath = path + Guid.NewGuid() + fileNa... ......

 

            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);
            }