Display All your favorites : Web Favorite « Windows System « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows System » Web FavoriteScreenshots 
Display All your favorites
Display All your favorites
 
Imports System
Imports System.Drawing
Imports System.Data
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms
Imports System.Drawing.Printing

Public Class MainClass
    Shared Sub Main()
        Dim Favorites As Favorites = New Favorites()

        Favorites.ScanFavorites()
        
        Dim As WebFavorite
     
        For Each f in Favorites.Favorites
          Console.WriteLine(f.Name)
        Next     
    End Sub
End Class



Public Class Favorites
    Public Favorites 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 Favorites Is Nothing Then Favorites = New _
                        WebFavoriteCollection()
        Dim scanFolder As New DirectoryInfo(folderName)

        Dim favoriteFile As FileInfo
        For Each favoriteFile In scanFolder.GetFiles
            If String.Compare(favoriteFile.Extension, ".url", TrueThen
                Dim favorite As New WebFavorite()
                favorite.Load(favoriteFile)
                Favorites.Add(favorite)
            End If
        Next
    End Sub
End Class

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 >= 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

Public Class WebFavorite
    Public Name As String
    Public Url As String

    Public Sub Open()
        System.Diagnostics.Process.Start(Url)
    End Sub

    Public Sub Load(ByVal fileInfo As FileInfo)
        Name = fileInfo.Name.Substring(0, _
            fileInfo.Name.Length - fileInfo.Extension.Length)

        Dim stream As New FileStream(fileInfo.FullName, FileMode.Open)
        Dim reader As New StreamReader(stream)
        Do While True
            Dim buf As String = reader.ReadLine
            If buf Is Nothing Then Exit Do
            If buf.StartsWith("URL="Then
                Url = buf.Substring(4)
                Exit Do
            End If
        Loop
        reader.Close()
        stream.Close()
    End Sub
End Class


           
         
  
Related examples in the same category
1.Get Web Favorite FolderGet Web Favorite Folder
2.Display Your Web Favorite CollectionDisplay Your Web Favorite Collection
3.Use Process to access favorite path
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.