I have an application that I'm developing in VB.NET. One function it has is to process input files from one directory and produce output files to another directory. I want the locations of these directories to be put into a flat file and read when the application begins. This will give administrators the ability to change the directory path without having to recompile the application. I have done this in Java using a .properties file. How is it done in VB.NET?Storing properties in VB.NET?
Here is a code sample from Microsoft
http://msdn.microsoft.com/en-us/library/
It basically scan's folders and files....all you'll need to do as add the part where you said to produce output files into a flat file....should be fairly straightforward.Storing properties in VB.NET?
Try this code. Use getDirs to open the file and get the input and output directories. The structure ';dirs'; is just a structure to store the input and output directories.
'Start code'
Const propFile = ';C:\PropFile.txt'; 'This is where the property file is stored
Structure dirs
Dim inputDir As String
Dim outputDir As String
End Structure
Function getDirs() As dirs
Dim content As String = My.Computer.FileSystem.ReadAllText(propF?br>
Dim data() As String
data = Split(content, ';,';)
Dim retVal As dirs
retVal.inputDir = data(0)
retVal.outputDir = data(1)
Return retVal
End Function
'End code'
In PropFile.txt, place the input and output directories on the same line, seperated by a comma. (input first, then output) like this:
C:\Input.txt,C:\Output.txt
So the admins only have to edit this file. Just remember to keep the comma.
To retrieve this info in the program, call the getDirs function, with the path to the properties file as its argument, and store the result in a variable of type ';dirs';. Then, use the inputDir and outputDir property of the variable to get the respective values. Like this:
Dim MyDirectories As dirs
MyDirectories = getDirs(';C:\PropFile.txt';)
Dim InputDirectory as String = MyDirectories.inputDir 'Holds inputDir
Dim OutputDirectory as string = MyDirectories.outputDir 'Holds outputDir
Hope this helps!
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment