如何存档想要替换它,如何下载文件并保存到programFiles。 [英] How to donwload file and save to programFiles, if exist want to replace it.

查看:117
本文介绍了如何存档想要替换它,如何下载文件并保存到programFiles。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我试图制作一个程序,要求用户下载该文件,并在下载后自动保存/替换正在从其文件夹下载的文件到程序文件目录。



但似乎它不起作用我花了5个小时搞清楚会发生什么但仍然没有运气可以有人帮我吗?



Hello im trying to make a program which asking the user to download the file and after downloading it automatically saving/replacing the file being downloaded from its folder to program files directory.

but it seems it doesn't work i spent 5hrs figuring out what happens but still no luck could someone pls help me?

Dim webClient As New System.Net.WebClient()

AddHandler webClient.DownloadProgressChanged, AddressOf progressChanged
        AddHandler webClient.DownloadFileCompleted, AddressOf downloadComplete

webClient.DownloadFileAsync(New Uri("WWW.MYURL.COM"), Environment.SpecialFolder.ProgramFiles & "\MYDIRECTORYFOLDERFROMPROGRAMFILES\")





有什么不对用我的代码?



我试图用我当前的环境位置声明这样的字符串





is there any wrong with my code?

ive tried to have declaration with my current environment location as string like this

dim currentFile as string
dim currentFile = Environment.SpecialFolder.ProgramFiles





并将其替换为





and replace it from

webClient.DownloadFileAsync(New Uri("WWW.MYFILEFROMWEBSIE.COM"), currentFile)





但它并没有&#; 39; t帮助!



请帮帮我:(



抱歉我的英文不好。



but it doesn't help!

pls help me :(

Sorry for my bad english.

推荐答案

您的目标目录 System.Environment.SpecialFolder.ProgramFiles ,或基于它的目录,不适合在运行时写入数据的位置。如果系统配置正确,则用户或未提升的代码不具有该权限。请参阅:

环境.SpecialFolder枚举(系统) [ ^ ]。



它可以是每个用户帐户设置的目录,或者在不常见的情况下,适用于所有用户,例如 LocalApplicationData ApplicationData CommonApplicationData ,依此类推。



-SA
Your target directory System.Environment.SpecialFolder.ProgramFiles, or a directory based on it, is not a suitable place to write data during runtime. If the system if properly configured, the user or the non-elevated code does not have permission for that. Please see:
Environment.SpecialFolder Enumeration (System)[^].

It could be the directory set up per user account or, in less usual cases, for all users, such as LocalApplicationData, ApplicationData, CommonApplicationData, and so on.

—SA


这篇关于如何存档想要替换它,如何下载文件并保存到programFiles。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆