Add your Web Link to the Favorites!

This is one of those cute little code snippets that you have a use for in practically every application. Applications that can do this look cool and intelligent—and it takes just a few simple lines of code. I’m talking about adding an Internet shortcut to the user’s Favorites menu.

How do you do it? Well, the following function encompasses all the logic for you. It accepts a page title and a URL. Then it locates the current Favorites folder (which could vary greatly depending on the machine setup) and creates a URL file in that folder, based on the title you passed. Inside that file, it includes a little required text for an Internet shortcut, alongside your URL. And that’s it—shortcut created!

Here’s the code:

Public Sub CreateShortcut(ByVal Title As String, ByVal URL As String)
    ' Creates a shortcut in the users Favorites folder
    Dim strFavoriteFolder As String
    ' Retrieve the favorite folder
    strFavoriteFolder = System.Environment.GetFolderPath( _
    ' Create shortcut file, based on Title
    Dim objWriter As System.IO.StreamWriter = _
    System.IO.File.CreateText(strFavoriteFolder & _
"\" & Title & ".url")
    ' Write URL to file
    objWriter.WriteLine("URL=" & URL)
    ' Close file
End Sub

To finish off this snippet, here are a couple of interesting calls to this procedure:

CreateShortcut("Karl", "")
CreateShortcut("Send mail to Karl Moore", "")

You might also like...


Karl Moore


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius