Library code snippets
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( _
Environment.SpecialFolder.Favorites)
' 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("[InternetShortcut]")
objWriter.WriteLine("URL=" & URL)
' Close file
objWriter.Close()
End Sub
To finish off this snippet, here are a couple of interesting calls to this procedure:
CreateShortcut("Karl Moore.com", "http://www.karlmoore.com/")
CreateShortcut("Send mail to Karl Moore", "mailto:karl@karlmoore.com")
Related articles
Related discussion
-
increase maxRequestLength in httpRuntime of Web.Config
by bussureddy82 (0 replies)
-
I don't want the Excel workbook to be visible to the users
by scot_in (0 replies)
-
Sharepoint : GroupBy results according to custom property
by sampadasanjay (0 replies)
-
i have struck with my project in vb.net
by jetski (4 replies)
-
Error in VB code
by glib162002 (0 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum)
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
Hi,
Check out this link, it gives an example of using the Add to Favourites dialog box, you may be able to adapt it:
http://vbnet.mvps.org/index.html?code/browse/shdocvwfav.htm
hi,
i want to use this fuction in Visual Basic 6 can you please help me to add web link to the favourites through VB6.
Regards
This thread is for discussions of Add your Web Link to the Favorites!.