Introduction
Autolink automatically generates a list of hyperlinks. You provide a list of htm pages (text file) and a list of page names (text file) as inputs and autolink creates an output file that contains a list of hyperlinks that you can embed in your source code.
Detail
This is a very very simple utility. It was written in ASP.NET. Its main function is to auto generate a list of hyperlinks (URLs). Recently i came across a simple project which required me to generate a list of urls for approximately 2000 files. Obviously it was a tedious task to do manually and could have wasted a lot of my precious time. I was certain that i would find a utility on the net to accomplish this simple task but to my surprise there was no such utility. After searhing internet comprehensively i found a small application that did this task but guess what, it's price was $395. So there was no solution left but to write a simple utility of my own. Code is very simple. I used streamReader class to read and write to the files. I used two files. One file contained list of pages and the other contained names of files. For example, list1 contains:
this_is_html_file1.htm
this_is_html_file2.htm
this_is_html_file3.htm
list2 contains:
this is html file1
this is html file2
this is html file3
You must be thinking that creating these files is a tedious job in itself. Yes, you are right! Its difficult to create these files manually but there is a solution to every problem and solution to our problem is using a DIR command in DOS mode. For example, folder contains 2000 files in it. How will you generate a list of files from this folder? Simple! Use following command at DOS Prompt:
Dir >
Execute this command in the folder that contains files. It will generate a list of all files. Use notepad to clean this list. Press Ctrl + H to run find and replace command. Remove dates from the list. Your file should only contain list of html files as shown above. Now, create another file by copying this file and run find and replace command once again. Remove .htm extension from each file. Now you have two files. One contains list of html files and the other contains list of names of those html files. Edit code and use your own paths. Locate ::Dim fylename As String = "C:\temp\list.txt":: in the code, this is your first file that contains list of html pages. Then locate ::Dim fylename2 As String = "C:\temp\list2.txt"::, this is your second file that contains list of names. Locate ::oWriter = oFile.CreateText("C:\temp\finallist.txt")::, this is your output file. Apply formatting to the contents of file1 and file2 and write results into file3. Later copy contents of file3 into your htm page. That's it! This utility is very helpful if you want to generate a list of urls for more than 100 files. I tried this utility and created a list of urls for 2000 files. It saved me lot of time. I know it should have contained a way to get a list of pages automatically so that we dont have to clean the list using notepad. May be if i get another project of creating a URL list for 10000 pages, i will add that functionality as well. You can modify the code and add that functionality yourself. Use Regular expressions to format the text file. Regexlib.com is a very helpful site and contains hundreds of pre-built regular expressions. You can download required regular expressions from that site. Lets briefly look at the code:
oStreamReader = File.OpenText(fylename)
This line instantiates ostreamreader object, fylename contains name of the file to be read.
oWriter = oFile.CreateText("C:\temp\finallist.txt")
This line instantiates owriter object, Use createtext method of file object to create a file.
Do
Line = oStreamReader.ReadLine
Line2 = ostreamreader2.ReadLine
newLine = "<font face='Verdana,Helvetica' size='2'><a href='" & Line & _
"'>" & Line2 & "</a></font><br>"
oWriter.WriteLine(newLine)
Loop Until Line Is Nothing
In this loop you read contents of both files line by line, apply formatting, create hyperlinks and write the result to the third file. User ReadLine method of streamreader class to read each line from the file. Use writeline method of streamwriter class to write each line to a new file.
'Destroy objects
oStreamReader.Close()
oStreamReader = Nothing
ostreamreader2.Close()
ostreamreader2 = Nothing
oWriter.Close()
oWriter = Nothing
In the end, destroy all objects. Its a good practice to manually destroy all objects in your code.
Happy programming!!