Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET File I/O and Registry (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/)
-   -   System can't find a .txt file location when compiled (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/327548-system-cant-txt-file-location-compiled.html)

BigHairy 04-01-2015 01:16 PM

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 = ""


passel 04-01-2015 03:48 PM

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.

    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)

BigHairy 04-02-2015 02:05 PM

Thanks. That did the trick!

All times are GMT -6. The time now is 01:08 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.