Hi,

What I want to know is how can I get Internet Explorer address bar information (URL)? When i`m type into address bar e.g. http://www.google.com, i want to get message with the same URL
e.g. Welcome to http://www.google.com How to get this?

Note: I will add a button for my application in the Command Bar in the Internet Explorer and when the user click on this button it will show to him a message box Contain the URL.

Can anyone help me?

Recommended Answers

All 13 Replies

You can use a function like -

public string GetCurrentPageName()
 {     string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);    
 string sRet = oInfo.Name;  
   return sRet; 
}
commented: c# code in vb.net forum. sorry AndreRet, nothing personal. +0

A million thanks to you Andre for your reply. But this is a code for C# can you convert it to a working VB.NET code. please :))

I'll convert this as soon as I get a chance.

A million thanks to you Andre for your reply. But this is a code for C# can you convert it to a working VB.NET code. please :))

You can do it by yourself, just go here http://www.developerfusion.com/tools/convert/csharp-to-vb/

But, seems that this code is not working on there. I think that you'll need to wait then.

You can also use this tool: http://fishcodelib.com/Convert.htm
But, it gives the same error.

Thank you Renan for this useful information but as you said it gives me an error when I convert the code from C# to VB.NET. So I will wait until Andre reply with the code of the VB.NET

Thank you all :)

Sorry, it was a hectic day here at the office. Will post as soon as I get a chance, probably first thing in the morning (10 hours or so from now):)

Andre I will kidnap you because you are a very nice man. Thank you so much for your interesting to help me :)

I will put a version of my software here when I am done with it.

Thank you all :)

commented: Thanks +7

Thanks, I'm off to home now. Will talk tomorrow.

Thanks a lot Andre. I want to say that I am not in rush so take your time and have a rest and when you become free you can post the code here ;)

I hope the following is what you need.

To get the current query string you would simply do something like the following:

Dim query as String = Request.QueryString("d")

This will assign the value of the "d" querystring to the string variable "query". Note that all query string values are strings, so if you're passing numbers around, you'll need to "cast" or convert those string values to numerics (be careful of exceptions when casting, though). For example:

Dim query as String = Request.QueryString("d")
Dim iquery as Integer = CType(query, Integer)

The QueryString property of the Request object is a collection of name/value key pairs. Specifically, it's of type System.Collections.Specialized.NameValueCollection, and you can iterate through each of the name/value pairs as so:

Dim coll As System.Collections.Specialized.NameValueCollection = Request.QueryString
Dim value As String
For Each key As String In coll.AllKeys
   value = coll(key)
Next

Now just use "value" where you need it.:)

Hi Andre,
Is the previous code to get the URL form the Internet browser??? because I didn't understand anything :(

what I want is when I run my application from the Internet Explorer browser it will show to me in message box the current URL. That's all :)

Where are you Andre??? I need your help :(

Sorry dude. I was moving to larger offices, so all my time went into setting everything up and get going again.:)

What you need is the following code (by another member here on DW:)) to get the url to a message box.
mshtml-->Add reference microsoft.mshtml
SHDocVw--> Go to Add Reference-->Go to Broese tab-->C:--Windows--System32--shdocvw.dll

Imports mshtml
Imports SHDocVw
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
 
 
Public Class Form1
 
    Public Const BaseKey As String = "SOFTWARE\Microsoft\Internet Explorer\Extensions"
    Public Const SubKey As String = "{10954C80-4F0F-11d3-B17C-00C0DFE39736}"
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim reg As RegistryKey = Registry.LocalMachine
        Dim sk As RegistryKey = reg.OpenSubKey(BaseKey, True)
        sk = sk.CreateSubKey(SubKey)
 
        sk.SetValue("ButtonText", "Button")
        sk.SetValue("CLSID", "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}")
        sk.SetValue("Default Visible", "Yes")
        sk.SetValue("Exec", "D:\Working\IEToolbarButtons\IEToolbarButtons\bin\Debug\IEToolbarButtons.exe")
        sk.SetValue("HotIcon", "C:\Windows\System\setup.ico")
        sk.SetValue("Icon", "C:\Windows\System\setup.ico")
        sk.Close()
        reg.Close()
 
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim browser As SHDocVw.InternetExplorer
        Dim myLocalLink As String
        Dim myDoc As mshtml.IHTMLDocument2
        Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindows()
        Dim filename As String
 
        For Each ie As SHDocVw.InternetExplorer In shellWindows
            filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower()
 
            If filename = "iexplore" Then
                browser = ie
                myDoc = browser.Document
                myLocalLink = myDoc.url
                MessageBox.Show(myLocalLink)
            End If
        Next
 
        End
 
    End Sub
End Class

The above is a lot of code to use just to return the url, but there is some more functions to it.

a Very short way is to use -

Dim CurrentURL As String = Request.Url.AbsoluteUri

'Messagebox = CurrentUrl...

Or, lastly.....

Dim MySite As String
MySite = Request.Url.ToString
Label1.Text = MySite

I hope any of the above helps.;)

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.