一、首先建一个单个书签的类WebFavorite


1

2

3


4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

二、建书签集合的类WebFavoriteCollection


Public Class WebFavoriteCollection
Inherits CollectionBase
Public Sub Add(ByVal Favorite As WebFavorite)
List.Add(Favorite)
End Sub
Public Sub Remove(ByVal Index As Integer)
If Index > 0 And Index < Count Then
List.Remove(Index)
End If
End Sub
Public ReadOnly Property Item(ByVal Index As Integer) As WebFavorite
Get
Return CType(List.Item(Index), WebFavorite)
End Get
End Property
End Class
三、建Favorites类获取收藏夹数据


Public FavoritesCollection As WebFavoriteCollection
Public ReadOnly Property FavoritesFolder() As String
Get
Return Environment.GetFolderPath(Environment.SpecialFolder.Favorites) '返回系统收收藏夹存储的位置
End Get
End Property
Public Sub ScanFavorites()
ScanFavorites(FavoritesFolder)
End Sub
Public Sub ScanFavorites(ByVal folderName As String)
If FavoritesCollection Is Nothing Then
FavoritesCollection = New WebFavoriteCollection
End If
For Each strFile As String In My.Computer.FileSystem.GetFiles(folderName)
My.Computer.FileSystem.GetFiles(folderName)
If strFile.EndsWith(".url", True, Nothing) Then
Try
Using objWebFavorite As New WebFavorite '用Using确保系统资源及时回收
objWebFavorite.Load(strFile)
FavoritesCollection.Add(objWebFavorite)
End Using
Catch ExceptionErr As Exception
Throw New Exception(ExceptionErr.Message)
End Try
End If
Next
End Sub
有了以上三个类我们就可以在程序窗体中调用
下载源码:/Files/quejuwen/Favorites.rar
使用现有的三个类,我们还可以建立任务栏程序如: