在 VB.net 中获取 DataDirectory 路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18568897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
To Get DataDirectory Path in VB.net?
提问by Techno Cracker
I have Access Database in \bin\debug..I am creating one utility to take Backup.So that I need to get the path of database..After that i will copy that file from that location to other location..So plz help me to get path.
我在 \bin\debug 中有访问数据库..我正在创建一个实用程序来进行备份.所以我需要获取数据库的路径..之后我将该文件从该位置复制到其他位置..所以请帮忙我得到路径。
回答by Satish Sojitra
You have to set in your database property to replace on each build .. so you will get fresh copy of your database while each build/deploy of your project at your bin directory using
您必须在您的数据库属性中设置以在每次构建时替换 .. 这样您将在每次构建/部署项目时使用您的 bin 目录获得数据库的新副本
My.Application.Info.DirectoryPath
回答by inquisitive
My.Application.Info.DirectoryPath
My.Application.Info.DirectoryPath
Gives you the directory where the startup exe is located
给你启动exe所在的目录
回答by LeftyX
AppDomain.CurrentDomain.BaseDirectory
AppDomain.CurrentDomain.BaseDirectory
gives you the name of the directory where your application has been started.
为您提供应用程序启动目录的名称。
Code:
代码:
Dim databasePath As String = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "creation.mdb")
回答by Techno Cracker
path = Application.StartupPath & "\creation.mdb"
If My.Computer.FileSystem.FileExists(path)
Then
MessageBox.Show("File is available")
Else
MessageBox.Show("File is Not available")
End If
I tried and it works.
我试过了,它有效。

