System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled
System can't find a .txt file location when compiled System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
Go Back  Xtreme Visual Basic Talk > > > System can't find a .txt file location when compiled


Reply
 
Thread Tools Display Modes
  #1  
Old 04-01-2015, 02:16 PM
BigHairy BigHairy is offline
Newcomer
 
Join Date: Feb 2015
Posts: 4
Default System can't find a .txt file location when compiled


Hi All,
I'm very new to VB and programming in general. I am writing a program that read parameters from a txt file, allows user to edit them and then rewrites the txt file. The txt file needs to exist in the executable directory so that it can be edited outside of the program, if necessary. When I install the compiled program I keep getting the following error:

"System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\JVINSON\AppData\Local\Apps\2.0\W2BKQPZZ.8Z4\H98Q0DNN.LY6\sci n..tion_a25ae97b7d90e261_0001.0000_9802acfcf808e9a7\OCECPAR\SCInstrume ntParameter.txt'."

Here is what I think is the only relevant part of the program code. In case it's relevant, the directory I in which I am compiling the executable is: "C:\RT-Dummy"
Dim fullpath As String = System.Reflection.Assembly.GetExecutingAssembly().Location

Dim ThisDir As String = My.Computer.FileSystem.GetParentPath(fullpath)

Dim FilePath As String = ThisDir & "\OCECPAR\SCInstrumentParameter.txt"

Dim ReadParFile As New StreamReader(FilePath)

word = ReadParFile.ReadLine().Split("'")(0)
labelHe1B3Current.Text = (GetParameters(word)(0))
labelHe1B2Current.Text = (GetParameters(word)(1))
labelHe1B1Current.Text = (GetParameters(word)(2))
labelHe1ACurrent.Text = (GetParameters(word)(3))
textHe1B3New.Text = ""
textHe1B2New.Text = ""
textHe1B1New.Text = ""
textHe1ANew.Text = ""

ReadParFile.Close()

Last edited by BigHairy; 04-01-2015 at 02:34 PM.
Reply With Quote
  #2  
Old 04-01-2015, 04:48 PM
passel's Avatar
passelSystem can't find a .txt file location when compiled passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

That is a temporary path, which is where the code is running, not where it is permanently located.
See if you can use the path to where the assembly is permanently located instead.
Dim fullpath as String = System.Reflection.Assembly.GetExecutingAssembly().CodeBase

edit: I just tried it. The CodeBase returns a URL, so you have to modify it.
Perhaps there is a method to do it, but I just manually did it.
Code:
    Dim fullpath As String = System.Reflection.Assembly.GetExecutingAssembly().CodeBase
    fullpath = fullpath.Replace("file:///", "")
    fullpath = fullpath.Replace("/"c, "\"c)
    Dim ThisDir As String = My.Computer.FileSystem.GetParentPath(fullpath)
'...
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 04-01-2015 at 04:59 PM.
Reply With Quote
  #3  
Old 04-02-2015, 03:05 PM
BigHairy BigHairy is offline
Newcomer
 
Join Date: Feb 2015
Posts: 4
Default

Thanks. That did the trick!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
 
System can't find a .txt file location when compiled
System can't find a .txt file location when compiled
 
-->