the file, the filename, and the file extension (for example, C:\Documents and Settings\Thearon\ Favorites\Extensible Markup Language (XML).url). What you have to do is extract only the filename from the complete path.
You do this by using the objFileInfo object, which has been initialized to an instance of the File Info class with the fileName variable passed to it. The FileInfo class provides several methods that return the various parts of the complete file path and name, such as only the filename and only the file extension.
You use the Name property of the objFileInfo object to get just the filename and extension of the file without the path, and you use the Substring method of the Name property to extract the filename minus the file extension. To supply the parameters to the Substring method, you also use the Length property of the Name property in the objFileInfo object to determine how long the filename is and the Length property of the Extension property to determine how long the file extension is.
So basically what you’re saying here is, “Take a substring, starting at the first character, and continue for the complete length of the string minus the length of the Extension property.” This, in effect, removes the .url from the end. Remember that the array of characters that make up a string is zero-based; thus you specify a starting position of 0 for the SubString method.
‘Set the Name member to the file name minus the extension Name = objFileInfo.Name.Substring(0, _
objFileInfo.Name.Length - objFileInfo.Extension.Length)
You read the entire contents of the file next into the strData. Because you are reading from a file, you’ll want to encapsulate the logic in a Try . . . Catch block to handle any IO exceptions that might occur.
The first thing that you do in this Try . . . Catch block is read the entire contents of the file into the strData variable. This is done using the My.Computer namespace and the ReadAllText method of the FileSystem class. This method will handle all the details of opening the file, reading the entire contents, closing the file, and releasing the resources used to perform these operations.
Try
‘Read the entire contents of the file
strData = My.Computer.FileSystem.ReadAllText(fileName)
After the contents of the file have been read, the strData variable will contain something similar to the data shown here. This is the data from the C:\Documents and Settings\Thearon\Favorites\Extensible Markup Language (XML).url shortcut file.
[DEFAULT]
BASEURL=http://www.w3.org/XML/
[InternetShortcut]
URL=http://www.w3.org/XML/
Modified=B0C9EC877EB3C401E2
Now that you have the entire contents of the favorite’s shortcut file in a single string variable, you want to split the contents of the strData variable into separate lines. This is done using the Split method of the String class, from which the strData variable is derived. The Split method is an overloaded method, and the version that you are using here accepts an array of strings that separate each line as the first parameter and the split options as the second parameter.