hey frnds, I want to add all the favorite names & its URL in litsview.I m able to get favorite names but not its urls. Can somebody know how to get URLs.

Code below gets the favorite names-

Private Sub GetFavorites()

              Dim di As DirectoryInfo
        Dim lPos As Integer
        Dim sData As String
        Dim arrFi As FileInfo() = Nothing

        di = New DirectoryInfo("C:\Documents and Settings\Administrator\Favorites")

        arrFi = di.GetFiles("*.*", SearchOption.AllDirectories)
        For Each fi As FileInfo In arrFi
            lPos = InStrRev(fi.FullName, "\", Len(fi.FullName))
            sData = Mid(fi.FullName, lPos + 1)
            sData = Replace(sData, ".url", "")
               Application.DoEvents()
        Next
    End Sub

Recommended Answers

All 5 Replies

Here's a code ripped from my old app

Public Sub ParseUrlFile(ByVal FileName As String, ByRef NewUrl As String)
  ' Return URL from the url-file
  '
  Dim FileStr As String
  Dim OneLine() As String
  Dim i As Integer
  Dim j As Integer

  Const PROCNAME As String = "ParseUrlFile"

  Try
    NewUrl = ""
    FileStr = My.Computer.FileSystem.ReadAllText(FileName)
    OneLine = FileStr.Split(CChar(Environment.NewLine))

    For i = 0 To OneLine.GetUpperBound(0)
      If OneLine(i).Trim.ToUpper = "[INTERNETSHORTCUT]" Then
        ' Get next url
        For j = i To OneLine.GetUpperBound(0)
          If OneLine(j).Trim.Length > 4 Then
            If OneLine(j).Trim.Substring(0, 4).ToUpper = "URL=" Then
              ' Drop "URL=" from the beginning of the line
              NewUrl = OneLine(j).Trim.Substring(4, OneLine(j).Trim.Length - "URL=".Length)
              Exit Sub
            End If
          End If
        Next j
      End If
    Next i
  Catch ex As Exception
    ' Handle errors
  End Try

End Sub

Line NewUrl = OneLine(j).Trim.Substring(4, OneLine(j).Trim.Length - "URL=".Length) was slightly modified (and not tested) for this posting, so there may be some "off-by-one" or similar error.

Hey thx very much frnd.....

Hi! Nice to hear that you got answer to your problem. Could you please mark the thread as solved. Thank you!

Sir I marked it as resolved.....

Tested code that give desired results.

Private Sub LoadFavorites()

        'LISTVIEWITEM OBJECT FOR ADDING NEW ITEMS TO LISTVIEW
        Dim LVI As ListViewItem = Nothing

        'STRING TO HOLD URL WE WILL EXTRACT
        Dim URL As String = String.Empty

        'GRAB ALL FILES WITH .URL EXT FROM THE FAVORITES DIR OF CURRENT USER, AND LOOP EACH FILE NAME
        For Each S As String In My.Computer.FileSystem.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Favorites), FileIO.SearchOption.SearchAllSubDirectories, "*.URL")

            'CREATE NEW LISTVIEW ITEM FROM THIS FILE, USE IO.PATH.GETFILENAME TO GET THE FILE NAME ONLY FROM PATH
            LVI = New ListViewItem(IO.Path.GetFileName(S))

            'USE A STREAMREADER TO OPEN THE FILE
            Using SReader As New IO.StreamReader(S)

                'LOOP THE FILE UNTIL WE FIND THE LINE THAT HAS THE URL, OR UNTIL WE HIT THE END OF THE FILE
                Do Until SReader.EndOfStream OrElse URL.StartsWith("URL=")
                    URL = SReader.ReadLine()
                Loop

                'REPLACE THE "URL=" PART OF THE TEXT WITH AN EMPTY STRING LEAVING ONLY THE URL
                URL = URL.Replace("URL=", String.Empty)

                'ADD THE URL STRING TO THE SECOND COLUMN IN LISTVIEW
                LVI.SubItems.Add(URL)

                'ADD LISTVIEWITEM TO THE LIST
                ListView1.Items.Add(LVI)

            End Using

            Application.DoEvents()
        Next

    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.