Simple resource question  
Author Message

PostPosted: Visual C# Language, Simple resource question Top

I am semi new to Visual C and have a question about adding resources or items. I have a program that I created that needs to read from a file. This file only contains a small amount of data. My question is, if I add an item such as a text file, is this file compiled in to the the program code or is the file external to the program
Is there a better way to do what I am trying to do. My simple project just stores a number and reads the file when the machine boots to repopulate the field with the number in the file.
Thanks for your help in advance,

Visual C#3  
Paul Louth

PostPosted: Visual C# Language, Simple resource question Top

Well if all you need is a simple number that's compiled with the program, why don't you just create a static variable   Because once you compile it in, it's not possible to modify it externally.

public static class MySettings
    public static int MyNumber = 42;

If you wish to modify it later without compilation then you should use an external file, in which can just load it using File.Open / File.OpenText:

using( StreamReader reader = File.OpenText("myTextFile.txt") )
    string contents = reader.ReadToEnd();
    int myNumber = Convert.ToInt32(contents);

Even better would be to stick the number into your application settings (double click on Properties in the Solution Explorer):

int myNumber = Settings.Default.MyNumber;

If you need more details on any of these then please let me know.


PostPosted: Visual C# Language, Simple resource question Top

Thanks for your response. How does the application settings work
What I am doing is creating my own windows restart program. When I set the value in the program I need to read it when the machine boots so that the program will restart again the next day.
I got the whole thing to work with the StreamReader but the path I was using was the debug path from my project. After publishing the program that path will no longer exist, that is where my problem is.