Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What i'm trying its open text file like this:
Dim FILE_NAME As String = "C:\FileName.txt"

If System.IO.File.Exists(FILE_NAME) = True Then
    Process.Start(FILE_NAME)
Else
    MsgBox("File Does Not Exist")
End If

But the problem is that, when i give my .exe with those files to another user, he might have another name of HardDrive, D: except C: for example.. therefore this:
"C:\FileName.txt"
will not find a file. I dont need openfiledialog. How to solve it? It would the best if i can put .txt file in same folder with .exe and some cmd will know that it should open file only from this folder.. just guessing... thanks in further

What I have tried:

Dim FILE_NAME As String = "C:\FileName.txt"

If System.IO.File.Exists(FILE_NAME) = True Then
    Process.Start(FILE_NAME)
Else
    MsgBox("File Does Not Exist")
End If
Posted
Updated 24-Jun-17 4:20am
v4

Use a configuration file: Managing Application Settings (.NET)[^]
 
Share this answer
 
Comments
JeezyWonder 24-Jun-17 8:17am    
Is it an app.config usage?
OriginalGriff 24-Jun-17 8:21am    
Yes - the link does say that.
JeezyWonder 24-Jun-17 8:36am    
too bad that mdsn doesnt provide too much code example with "configuration text files", honestly cant get the point of app.config
OriginalGriff 24-Jun-17 8:44am    
That's because the code is trivial:
Dim myString as String = Properties.Settings.Default.MyStringSetting
...
Properties.Settings.Default.MyStringSetting = myNewStringValue
Properties.Settings.Default.Save()

The data is stored in an XML file so it's simple to edit outside the app if you need to.
JeezyWonder 24-Jun-17 9:40am    
Yes, could you be so kind to provide example how to assign 8000 chars(i have them in text file now, so i will just copy) to the app.config string? then get it from it, when i need it in the code, like this? :
Dim myString as String = Properties.Settings.Default.MyStringSetting
myString = '8000 chars here
Properties.Settings.Default.MyStringSetting = myNewStringValue
Properties.Settings.Default.Save()
(then it will be saved in xml as i understnad? and how to get chars back from xml and assign to new var?)
To get the system drive in C# you can use:
C#
var p = System.IO.Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
In Vb.NET:
VB
Dim p = System.IO.Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System))
To get the path where the exe is:
VB
Dim strPath As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
Your will have to remove the begin of the string "file:\\" though.
 
Share this answer
 
v3
Comments
JeezyWonder 24-Jun-17 10:33am    
So "p" will contain a System drive info? how to use it?
Dim FILE_NAME As String = "C:\FileName.txt"
RickZeeland 24-Jun-17 10:39am    
It will be a string which contains the drive letter, e.g. "D:".
Just concatenate with your filename, or better: use Path.Combine()
JeezyWonder 24-Jun-17 10:47am    
Dim FILE_NAME As String = p +"\FileName.txt" - Will work?
RickZeeland 24-Jun-17 10:49am    
Just try don't be afraid :) might be that you don't have to use the '\' in the filename, so it is better to use Path.Combine() which will add that automatically if needed.
JeezyWonder 24-Jun-17 11:20am    
Thanks very much, one more qeustion, drive problem solved with your provided help, but how to resolve folder path problem? User can exctract my folder with my .exe and .txt files on just "C:\" or On "C:\Detskop" or another C drive folder, thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900