Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 下载到根目录_Vb.net_Directory_Root - Fatal编程技术网

Vb.net 下载到根目录

Vb.net 下载到根目录,vb.net,directory,root,Vb.net,Directory,Root,好吧,我找了很久才找到这个,但运气不好 我正在使用: Me.downloader.DownloadFileAsync(New Uri(fileUrl), Path.GetFileName(fileUrl), Stopwatch.StartNew) 下载一个文件,但我希望它保存到我的程序的根目录中一个名为launcher的文件中 例如,如果我的程序在桌面上,我打开它,然后单击“开始”,我希望它创建launcher文件夹,如果它丢失了,则将文件下载到该文件夹中,如果没有,则将文件下载到该文件夹中

好吧,我找了很久才找到这个,但运气不好

我正在使用:

Me.downloader.DownloadFileAsync(New Uri(fileUrl), Path.GetFileName(fileUrl), Stopwatch.StartNew)
下载一个文件,但我希望它保存到我的程序的根目录中一个名为launcher的文件中

例如,如果我的程序在桌面上,我打开它,然后单击“开始”,我希望它创建launcher文件夹,如果它丢失了,则将文件下载到该文件夹中,如果没有,则将文件下载到该文件夹中

我一直在到处寻找能让我做到这一点的代码,我尝试了很多不同的方法

目前,它只是保存在程序所在的根目录中


谢谢。

试试这样:

Dim baseDir As String = AppDomain.CurrentDomain.BaseDirectory
Dim launcherDir As String = Path.Combine(baseDir, "Launcher")

If Not Directory.Exists(launcherDir) Then
   Directory.CreateDirectory(launcherDir)
End If

Dim targetFile = Path.Combine(launcherDir, Path.GetFileName(fileUrl))

Me.downloader.DownloadFileAsync(New Uri(fileUrl), targetFile, Stopwatch.StartNew)

需要知道您使用的是什么操作系统以及程序是如何安装的。较新的操作系统不允许写入程序文件夹,而是强制您写入应用程序的ProgramData文件夹或用户数据空间。这主要是因为应用程序不再像在XP和以前版本的windows中那样具有管理权限。我正在vb.net中制作一个程序,并且我使用的是windows 7,该程序应该可以在所有操作系统上运行。windows 7将不允许应用程序在程序目录中写入,除非它以管理员身份运行。很好,它可以工作。非常感谢你。我想你写代码很快,因为有一些bug。你写了'Dim laucherDir,但使用了变量'launcherDir,这让我开始感到困惑,但后来我发现这是一个打字错误。另外,Create不是Directory的一部分,我必须将其更改为Directory.CreateDirectory。除此之外,这个很好用,谢谢你抽出时间。