Hi,

I am using VS2008 and for the project I am creating, I have a "settings" text file I am using to save user defined settings like color theme, homepage, etcetera. It works fine, however, I am unsure as to how to handle the eventual distributed apps' destination folder/file.

Creating a pre-determined folder/file is easy enough, but what I'd like to do is make it part of the installed folder files, which should be:

C:\Program Files\MyApp\

I tried creating the file if it wasn't found, however this did not happen (Though I specified the above formatted pathway) perhaps because I was in debug but it should have saved the text file, which it did not and wasn't found anywhere after saving/creating one.

I have the InnoSetup application (Looks great BTW) and see I can include a starting default text file AND make a specific directory for it, but I am unsure as of yet how Inno works exactly, but would prefer testing it through debug before an install anyway. Wish SHOULD be able to be done, am I right?

The odd thing is that although the file was NOT created as specified when creating one, it DID save a setting when I re-ran/debugged the app. (Rather odd, how is this happening I wonder?)

Here is how I am trying to resolve my problem...

' When it doesn't find a file, call save routine

            MsgBox("ERROR! Setting File Not Found! Creating a new one...")
            SaveSettings()
        End If

    Sub SaveSettings()
        Dim strFile As String = "C:\Program Files\MyAppName\settings.txt"
        If System.IO.File.Exists(strFile) = True Then
            Dim objStreamWriter As New System.IO.StreamWriter(strFile)
            objStreamWriter.WriteLine(strTheme)
            objStreamWriter.WriteLine(strHomePage)
            objStreamWriter.WriteLine("eof")
            objStreamWriter.Close()
            MsgBox("Settings Saved!")
        Else
            Dim objStreamWriter As New System.IO.StreamWriter(strFile)
            objStreamWriter.WriteLine(strTheme)
            objStreamWriter.WriteLine(strHomePage)
            objStreamWriter.WriteLine("eof")
            objStreamWriter.Close()
            MsgBox("New Settings File Created!")
        End If

So I am also wondering... if I use the InnoSetup to "set up" the directory and file, and it is according to user-defined destination, how do I reflect that decision in my coding for reading and writting the file?

I could simply use a basic path like C:\DATAFILES\ but this wouldn't be very professional, though fine for development purposes. Excuse any n00bish-ness LOL. Any help would be awesome. THANX!

-Tom

You can use Application.StartUpPath when working with folders originating from the application folder.
Application.StartUpPath gives you the full path for the application executable without the executable file.

Then it's a simple matter of string concatination.

Dim fileName As String = Application.StartupPath & "\subfolder\filename.txt"

You can use Application.StartUpPath when working with folders originating from the application folder.
Application.StartUpPath gives you the full path for the application executable without the executable file.

Then it's a simple matter of string concatination.

Dim fileName As String = Application.StartupPath & "\subfolder\filename.txt"

Awesome, thank you! I will add this to my project. I know there is an option called "MySettings" or sumsuch, but this will do just fine, for now. I appreciate you taking the time to reply!

This question has already been answered. Start a new discussion instead.