a question about config file for windows service program
-
i have windows service program,and i want to make a config file for it. if the config file is placed in the directory:system32/,i can access it by System.Environment.SystemDirectory,but when placed in the windows service executable files' directory(bin\debug\),i don't know how to access it.
-
i have windows service program,and i want to make a config file for it. if the config file is placed in the directory:system32/,i can access it by System.Environment.SystemDirectory,but when placed in the windows service executable files' directory(bin\debug\),i don't know how to access it.
You don't need to access the file directly. Use the classes in the system.configuration namespace to access the configuration file. If you just have simple string data to access then you can use the AppSettings class and section. Otherwise you can write your own section handler. The file should be named yourexe.exe.config, but vs.net will copy any file named app.config from the root of your project to the output directory and rename it to the proper name so your service will read it.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
-
You don't need to access the file directly. Use the classes in the system.configuration namespace to access the configuration file. If you just have simple string data to access then you can use the AppSettings class and section. Otherwise you can write your own section handler. The file should be named yourexe.exe.config, but vs.net will copy any file named app.config from the root of your project to the output directory and rename it to the proper name so your service will read it.
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
o,thank you very much.