VB.Net - Saving settings on a text file; finding bin folder
-
Language - Visual Basic.Net (home edition, or the non-proffessional at any rate) Okay, I have a problem with three parts. Part the first: I want to be able to save certain settings of a program to a text file. Now, I know how to create a text file and write to it, but I need to be able to read specific lines from it, and I'm not really sure how to do that. Part the second: I need to find the bin folder (or whatever folder the program is running in) at runtime, so that I can figure out where the text file is. Part the third: I need to know how to confirm whether or not that text file already exists. Any help at all would be greatly appreciated. Thanks!
-
Language - Visual Basic.Net (home edition, or the non-proffessional at any rate) Okay, I have a problem with three parts. Part the first: I want to be able to save certain settings of a program to a text file. Now, I know how to create a text file and write to it, but I need to be able to read specific lines from it, and I'm not really sure how to do that. Part the second: I need to find the bin folder (or whatever folder the program is running in) at runtime, so that I can figure out where the text file is. Part the third: I need to know how to confirm whether or not that text file already exists. Any help at all would be greatly appreciated. Thanks!
RandomGuy85 wrote: Part the first: I want to be able to save certain settings of a program to a text file. Now, I know how to create a text file and write to it, but I need to be able to read specific lines from it, and I'm not really sure how to do that. Pretty much the same way that you write to the file. First, how are you writing to the file? There are different classes and methods for File I/O and I'd like to match the technique with what your already doing. A sample of your code would help. Part the second: I need to find the bin folder (or whatever folder the program is running in) at runtime, so that I can figure out where the text file is. You can get the path to the executable from Application.StartupPath. The only problem with what you are doing is that every user that saves setting from your application will overwrite the previous users settings. A better choice would be to use the path stored in Application.UserAppDataPath. Part the third: I need to know how to confirm whether or not that text file already exists. Easy enough...You can use File.Exists(filepath) to see if the file exists or not. This is a good excersize in reading/writing files...but there is another way to do application settings without them. SaveSetting and GetSetting will allow you to read and write settings to the registry without having to handle files at all. RageInTheMachine9532
-
RandomGuy85 wrote: Part the first: I want to be able to save certain settings of a program to a text file. Now, I know how to create a text file and write to it, but I need to be able to read specific lines from it, and I'm not really sure how to do that. Pretty much the same way that you write to the file. First, how are you writing to the file? There are different classes and methods for File I/O and I'd like to match the technique with what your already doing. A sample of your code would help. Part the second: I need to find the bin folder (or whatever folder the program is running in) at runtime, so that I can figure out where the text file is. You can get the path to the executable from Application.StartupPath. The only problem with what you are doing is that every user that saves setting from your application will overwrite the previous users settings. A better choice would be to use the path stored in Application.UserAppDataPath. Part the third: I need to know how to confirm whether or not that text file already exists. Easy enough...You can use File.Exists(filepath) to see if the file exists or not. This is a good excersize in reading/writing files...but there is another way to do application settings without them. SaveSetting and GetSetting will allow you to read and write settings to the registry without having to handle files at all. RageInTheMachine9532
Using the registry is not the ".NET Way", for what it's worth. Also, I believe you need additional CAS permissions to do so that are not required when using isolated storage. Charlie Here I am. Love me.
-
Using the registry is not the ".NET Way", for what it's worth. Also, I believe you need additional CAS permissions to do so that are not required when using isolated storage. Charlie Here I am. Love me.
Charlie Williams wrote: Using the registry is not the ".NET Way", for what it's worth. Also, I believe you need additional CAS permissions to do so that are not required when using isolated storage. The '.NET Way'?? Are you talking about XML config files? The Save/GetSetting write their information to the CurrentUser Key of the registry. Unless the desktop load has been severely restricted, no out of the ordinary permissions are required by the code or user to use these functions. RageInTheMachine9532
-
Charlie Williams wrote: Using the registry is not the ".NET Way", for what it's worth. Also, I believe you need additional CAS permissions to do so that are not required when using isolated storage. The '.NET Way'?? Are you talking about XML config files? The Save/GetSetting write their information to the CurrentUser Key of the registry. Unless the desktop load has been severely restricted, no out of the ordinary permissions are required by the code or user to use these functions. RageInTheMachine9532
I simply meant that Microsoft recommends against using the registry when there are other options available. Certainly, there is nothing wrong with using the registry to store app information on a Windows machine, but if you intend to port your app to other platforms (not that it's realistic to do so now, but that's one of the stated goals of .net in the first place, right?) you'll have to come up with a different way of doing it. GetSetting requires registry permissions. This isn't a problem with a locally installed app, but apps run over an intra/internet do not have this permission by default. If neither of those two issues apply to a given situation, then register away. ;) Charlie Here I am. Love me.