locked
Opening .URL file in WebBrowser Control

    Question

  • Hi,

     

    How would i display a .url files destination page in my webbrowser control?

     

    I've tried:

     

    WebBrowser.Navigate("c:\file.url")

     

    But this tries to OPEN the actual file instead of showing the shortcut to the page in the WebBrowser control.

     

     

    Friday, April 04, 2008 3:44 PM

Answers

  • Hi AlexCap,

    You can try using the following code snippet to get the string text. Then you need to parse string text to get Url. Finally use that Url to navigate in WebBrowser control.

          Dim str As String = My.Computer.FileSystem.ReadAllText("c:\google.url")
          MessageBox.Show(str)

    Best regards,
    Riquel
    Tuesday, April 08, 2008 1:42 PM
    Moderator
  • This should do what you need:

     

    Code Snippet

    Imports System.Text.RegularExpressions

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim rx As New Regex("(?<=URL=).*")

    Dim str As String = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Tek-Tips Home.url")

    Dim url As String = rx.Match(str).ToString

    rx = Nothing

    WebBrowser1.Navigate(url)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    WebBrowser1.Navigate(Regex.Match(My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Tek-Tips Home.url"), "(?<=URL=).*").ToString)

    End Sub

    End Class

     

     

    Button1 demonstrates a multi-line solution, whereas Button2 demonstrates a 1 line solution.

     

     

    Hope this helps.

     

    Wednesday, April 09, 2008 2:13 PM

All replies

  • Hi AlexCap,

    Could you tell us the content of file.url and the file type of file.url?

    Best regards,
    Riquel

    Monday, April 07, 2008 4:45 AM
    Moderator
  • Hi Smile

     

    Sorry for not being clear!

     

    I'm sure you know what is it but here it is:

     

    The .url file is created like a windows .lnk shortcut file.

     

    right click on the desktop, NEW>Shortcut

     

    type www.google.com click NEXT, click FINISH Smile

     

    I think the entension for this shortcut type is .url

     

    The reason why i have this is because my app lists the url files from a folder in a combo box, and i want it to launch the file into my webbrowser control Smile

     

     

     

    Monday, April 07, 2008 9:55 AM
  • Hi AlexCap,

    You can try using the following code snippet to get the string text. Then you need to parse string text to get Url. Finally use that Url to navigate in WebBrowser control.

          Dim str As String = My.Computer.FileSystem.ReadAllText("c:\google.url")
          MessageBox.Show(str)

    Best regards,
    Riquel
    Tuesday, April 08, 2008 1:42 PM
    Moderator
  • Hi this is the text that it comes up with:

     

    [InternetShortcut]

    URL=http://www.google.com/

    IDList=

    [{000214A0-0000-0000-C000-000000000046}]

    Prop3=19,2

     

    Could you tell me how to take the part after the URL= and store jus the actual URL?

    Wednesday, April 09, 2008 10:11 AM
  • This should do what you need:

     

    Code Snippet

    Imports System.Text.RegularExpressions

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim rx As New Regex("(?<=URL=).*")

    Dim str As String = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Tek-Tips Home.url")

    Dim url As String = rx.Match(str).ToString

    rx = Nothing

    WebBrowser1.Navigate(url)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    WebBrowser1.Navigate(Regex.Match(My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Tek-Tips Home.url"), "(?<=URL=).*").ToString)

    End Sub

    End Class

     

     

    Button1 demonstrates a multi-line solution, whereas Button2 demonstrates a 1 line solution.

     

     

    Hope this helps.

     

    Wednesday, April 09, 2008 2:13 PM
  • thanks for that guys!

     

    Thursday, April 10, 2008 7:34 AM