Installing a resource file with my application.

d3c4y

New member
Joined
Jul 25, 2009
Messages
2
Programming Experience
1-3
Hey,

I'm going to be using a text file to record and save values, line by line, and then pull these values out again upon restarting the application. Almost like a save file of sorts, just for some basic numeric variables.

Getting the information in and out won't be too much of an issue, however I am wondering if there is a way that during the installation of this application, I could specify a place to create and save this text file, for eg:

c:\ProgramFiles\POSx\stocklevels.text


I have VS8 Professional, so I do have the Setup Wizard tool, which may allow me to attach files. Would this work?

Is there a better way? Or am I best off just allowing the program to write to My Documents somewhere, and then access the file again from there?


Thanks.
 
Another option is to create it if it doesn't exist upon startup or when you need to write to it.
VB.NET:
Expand Collapse Copy
If Not IO.File.Exists("path") Then ' create it.
You also have this StreamWriter constructor:
StreamWriter(String, Boolean)

If the file exists, it can be either overwritten or appended to. If the file does not exist, this constructor creates a new file.
Resource files, as indicated by your thread title, is not meant to be writable.

If you need a data file to be included that has design time content, you can add it to project (Add existing, or in this case Add new item 'Text file'). For this have Build Action set to Content and Copy mode 'Copy if newer'. For ClickOnce deployment you would then configure 'Application Files' and select 'Data File' as publish status to make the setup publish it to the data folder. It might be more convenient to let publish status be default "Include", as it then will output to application path both for debugging and for deployment, which translates to Application.StartupPath, but I think it is not good practice to have writeable data files in the application folder. If you do configure as Data File there is another problem, with a debug build it outputs to the debug folder (StartupPath), but with deployment it outputs to data folder (UserAppDataFolder), so you'll end up with having to check the deployment status like this:
VB.NET:
Expand Collapse Copy
Dim path As String = String.Empty
If My.Application.IsNetworkDeployed Then
    path = IO.Path.Combine(Application.UserAppDataPath, "TextFile1.txt")
Else
    path = IO.Path.Combine(Application.StartupPath, "TextFile1.txt")
End If
 
Back
Top