Vb.net 试图使visual studio 2015中的项目在项目中使用txt.file,而不是使用usb驱动器
我有一个程序,我已经工作得很好。它正在使用e:\inventory中的txt文件运行。是否有一种方法可以将其添加到项目中,以便代码在不访问usb驱动器的情况下运行 我通过右键单击项目名称并添加一个新项目(文本文件)将其添加到项目中,这将它添加到解决方案资源管理器中。但是,我似乎不知道如何告诉代码在那里查找文件 目前我的代码是:Vb.net 试图使visual studio 2015中的项目在项目中使用txt.file,而不是使用usb驱动器,vb.net,visual-studio-2015,Vb.net,Visual Studio 2015,我有一个程序,我已经工作得很好。它正在使用e:\inventory中的txt文件运行。是否有一种方法可以将其添加到项目中,以便代码在不访问usb驱动器的情况下运行 我通过右键单击项目名称并添加一个新项目(文本文件)将其添加到项目中,这将它添加到解决方案资源管理器中。但是,我似乎不知道如何告诉代码在那里查找文件 目前我的代码是: Dim objReader As IO.StreamReader Dim strLocationAndNameOfFile As String = "e:
Dim objReader As IO.StreamReader
Dim strLocationAndNameOfFile As String = "e:\inventory.txt"
Dim intCount As Integer = 0
Dim intFill As Integer
Dim strFileError As String = "The file is not available. Restart when the file
is available."
' Verify the file exists.
If IO.File.Exists(strLocationAndNameOfFile) Then
objReader = IO.File.OpenText(strLocationAndNameOfFile)
如果文件与可执行文件位于同一目录中,则可以按名称引用该文件
在解决方案资源管理器中选择该文件,并在其属性中将其设置为
Copy if newer
。然后只需从路径中删除e:\
。太好了。非常感谢。这让我抓狂。