web browser ctrl - retrieve address for display in textbox?

G

Guest

Greetings,

I am using a web browser control to browse windows explorer. I give it a
default address as below and then click on some folder. The question is:
how do I retrieve the address of the folder I clicked on so that I can
display it in a textbox similar to windows explorer?

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref
null_obj_str, ref null_obj_str);

While I am at it, is there a back button mechanism that is already built
into .Net 2.0? Or do I have to go with my plan of noting all the addresses
that have been visited and then just navigating backwards from the list of
visited address that I store?

Thanks,
Rich
 
N

Nicholas Paldino [.NET/C# MVP]

Rich,

You should be able to look at the Document property of the web browser
control and then look at the Url property on the HtmlDocument instance
returned from that to get the current page location.

The WebBrowser control has a GoBack method on it that you can use to
navigate to the previous page.
 
G

Guest

Thank you for your reply. I am not familiar with the web browser control.
I amjust getting errors right now. May I ask for a simple example how I
would use the document protperty of the web browser? and the url property?

Thanks



Nicholas Paldino said:
Rich,

You should be able to look at the Document property of the web browser
control and then look at the Url property on the HtmlDocument instance
returned from that to get the current page location.

The WebBrowser control has a GoBack method on it that you can use to
navigate to the previous page.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Greetings,

I am using a web browser control to browse windows explorer. I give it a
default address as below and then click on some folder. The question is:
how do I retrieve the address of the folder I clicked on so that I can
display it in a textbox similar to windows explorer?

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref
null_obj_str, ref null_obj_str);

While I am at it, is there a back button mechanism that is already built
into .Net 2.0? Or do I have to go with my plan of noting all the
addresses
that have been visited and then just navigating backwards from the list of
visited address that I store?

Thanks,
Rich
 
N

Nicholas Paldino [.NET/C# MVP]

Rich,

It's just a property access, like so:

Uri url = webBrowser.Document.Url;

If you want the string representation of the Uri, then just call the
ToString method on the uri.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Thank you for your reply. I am not familiar with the web browser
control.
I amjust getting errors right now. May I ask for a simple example how I
would use the document protperty of the web browser? and the url property?

Thanks



Nicholas Paldino said:
Rich,

You should be able to look at the Document property of the web
browser
control and then look at the Url property on the HtmlDocument instance
returned from that to get the current page location.

The WebBrowser control has a GoBack method on it that you can use to
navigate to the previous page.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Greetings,

I am using a web browser control to browse windows explorer. I give it
a
default address as below and then click on some folder. The question
is:
how do I retrieve the address of the folder I clicked on so that I can
display it in a textbox similar to windows explorer?

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref
null_obj_str, ref null_obj_str);

While I am at it, is there a back button mechanism that is already
built
into .Net 2.0? Or do I have to go with my plan of noting all the
addresses
that have been visited and then just navigating backwards from the list
of
visited address that I store?

Thanks,
Rich
 
G

Guest

Thank you again for getting back to me. Here is what I tried:

Uri url = web1.Document.Url;

but it is error ing out. I guess I will have to wrestle with this for a
while.

I also tried

Console.WriteLine(web1.Document.Url.ToString)

but error said Object reference not set to instance of an object. If I
comment out the Console... then web1 displays the contents of the specified
folder.



Nicholas Paldino said:
Rich,

It's just a property access, like so:

Uri url = webBrowser.Document.Url;

If you want the string representation of the Uri, then just call the
ToString method on the uri.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Thank you for your reply. I am not familiar with the web browser
control.
I amjust getting errors right now. May I ask for a simple example how I
would use the document protperty of the web browser? and the url property?

Thanks



Nicholas Paldino said:
Rich,

You should be able to look at the Document property of the web
browser
control and then look at the Url property on the HtmlDocument instance
returned from that to get the current page location.

The WebBrowser control has a GoBack method on it that you can use to
navigate to the previous page.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greetings,

I am using a web browser control to browse windows explorer. I give it
a
default address as below and then click on some folder. The question
is:
how do I retrieve the address of the folder I clicked on so that I can
display it in a textbox similar to windows explorer?

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref
null_obj_str, ref null_obj_str);

While I am at it, is there a back button mechanism that is already
built
into .Net 2.0? Or do I have to go with my plan of noting all the
addresses
that have been visited and then just navigating backwards from the list
of
visited address that I store?

Thanks,
Rich
 
N

Nicholas Paldino [.NET/C# MVP]

Rich,

What is the exception you are getting? If you don't indicate what
exception is occuring, it's very difficult to figure out what the error is.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Thank you again for getting back to me. Here is what I tried:

Uri url = web1.Document.Url;

but it is error ing out. I guess I will have to wrestle with this for a
while.

I also tried

Console.WriteLine(web1.Document.Url.ToString)

but error said Object reference not set to instance of an object. If I
comment out the Console... then web1 displays the contents of the
specified
folder.



Nicholas Paldino said:
Rich,

It's just a property access, like so:

Uri url = webBrowser.Document.Url;

If you want the string representation of the Uri, then just call the
ToString method on the uri.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Thank you for your reply. I am not familiar with the web browser
control.
I amjust getting errors right now. May I ask for a simple example how
I
would use the document protperty of the web browser? and the url
property?

Thanks



:

Rich,

You should be able to look at the Document property of the web
browser
control and then look at the Url property on the HtmlDocument instance
returned from that to get the current page location.

The WebBrowser control has a GoBack method on it that you can use
to
navigate to the previous page.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greetings,

I am using a web browser control to browse windows explorer. I give
it
a
default address as below and then click on some folder. The
question
is:
how do I retrieve the address of the folder I clicked on so that I
can
display it in a textbox similar to windows explorer?

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj,
ref
null_obj_str, ref null_obj_str);

While I am at it, is there a back button mechanism that is already
built
into .Net 2.0? Or do I have to go with my plan of noting all the
addresses
that have been visited and then just navigating backwards from the
list
of
visited address that I store?

Thanks,
Rich
 
G

Guest

Well, here is what I am tyring now with no luck:

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref
null_obj_str, ref null_obj_str);

I added the lines below to the above. won't compile. (C# 2005)

HtmlDocument doc = this.axWebBrowser1.Document;
Uri url = doc.Url;
Console.WriteLine(url.ToString);



Nicholas Paldino said:
Rich,

What is the exception you are getting? If you don't indicate what
exception is occuring, it's very difficult to figure out what the error is.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Thank you again for getting back to me. Here is what I tried:

Uri url = web1.Document.Url;

but it is error ing out. I guess I will have to wrestle with this for a
while.

I also tried

Console.WriteLine(web1.Document.Url.ToString)

but error said Object reference not set to instance of an object. If I
comment out the Console... then web1 displays the contents of the
specified
folder.



Nicholas Paldino said:
Rich,

It's just a property access, like so:

Uri url = webBrowser.Document.Url;

If you want the string representation of the Uri, then just call the
ToString method on the uri.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thank you for your reply. I am not familiar with the web browser
control.
I amjust getting errors right now. May I ask for a simple example how
I
would use the document protperty of the web browser? and the url
property?

Thanks



:

Rich,

You should be able to look at the Document property of the web
browser
control and then look at the Url property on the HtmlDocument instance
returned from that to get the current page location.

The WebBrowser control has a GoBack method on it that you can use
to
navigate to the previous page.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greetings,

I am using a web browser control to browse windows explorer. I give
it
a
default address as below and then click on some folder. The
question
is:
how do I retrieve the address of the folder I clicked on so that I
can
display it in a textbox similar to windows explorer?

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj,
ref
null_obj_str, ref null_obj_str);

While I am at it, is there a back button mechanism that is already
built
into .Net 2.0? Or do I have to go with my plan of noting all the
addresses
that have been visited and then just navigating backwards from the
list
of
visited address that I store?

Thanks,
Rich
 
G

Guest

made some changes

HTMLDocument doc = (HTMLDocument)this.axWebBrowser1.Document;

Console.WriteLine(doc.url.ToString); //errors here

error says

Error 1 The best overloaded method match for
'System.Console.WriteLine(bool)' has some invalid arguments

Error 2 Argument '1': cannot convert from 'method group' to 'bool'

Rich said:
Well, here is what I am tyring now with no luck:

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj, ref
null_obj_str, ref null_obj_str);

I added the lines below to the above. won't compile. (C# 2005)

HtmlDocument doc = this.axWebBrowser1.Document;
Uri url = doc.Url;
Console.WriteLine(url.ToString);



Nicholas Paldino said:
Rich,

What is the exception you are getting? If you don't indicate what
exception is occuring, it's very difficult to figure out what the error is.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rich said:
Thank you again for getting back to me. Here is what I tried:

Uri url = web1.Document.Url;

but it is error ing out. I guess I will have to wrestle with this for a
while.

I also tried

Console.WriteLine(web1.Document.Url.ToString)

but error said Object reference not set to instance of an object. If I
comment out the Console... then web1 displays the contents of the
specified
folder.



:

Rich,

It's just a property access, like so:

Uri url = webBrowser.Document.Url;

If you want the string representation of the Uri, then just call the
ToString method on the uri.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thank you for your reply. I am not familiar with the web browser
control.
I amjust getting errors right now. May I ask for a simple example how
I
would use the document protperty of the web browser? and the url
property?

Thanks



:

Rich,

You should be able to look at the Document property of the web
browser
control and then look at the Url property on the HtmlDocument instance
returned from that to get the current page location.

The WebBrowser control has a GoBack method on it that you can use
to
navigate to the previous page.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Greetings,

I am using a web browser control to browse windows explorer. I give
it
a
default address as below and then click on some folder. The
question
is:
how do I retrieve the address of the folder I clicked on so that I
can
display it in a textbox similar to windows explorer?

object loc = "W:\\EP 2005";
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref null_obj, ref null_obj,
ref
null_obj_str, ref null_obj_str);

While I am at it, is there a back button mechanism that is already
built
into .Net 2.0? Or do I have to go with my plan of noting all the
addresses
that have been visited and then just navigating backwards from the
list
of
visited address that I store?

Thanks,
Rich
 
M

mpetrotta

made some changes

HTMLDocument doc = (HTMLDocument)this.axWebBrowser1.Document;

Console.WriteLine(doc.url.ToString); //errors here

error says

Error 1 The best overloaded method match for
'System.Console.WriteLine(bool)' has some invalid arguments

Error 2 Argument '1': cannot convert from 'method group' to 'bool'

ToString is a method, so you need to call it as you would other
methods (with parentheses around the parameters).

Back to your original issue: since you say you're using .NET 2.0, I
strongly suggest you use the native WebBrowser control
(System.Windows.Forms.WebBrowser) rather than the ActiveX-wrapped
kludge. It's more robust and easier to use.

Michael
 
G

Guest

Thank you for the tip. Actually, I figured out a couple of things (btw, I
confess that I am really a vB guy and was studying a sample I found in C# -
forgot about the parens - lazy vb guy - the IDE puts em in for me). But I am
able to get the current url from the documentcompleted event of the web
browser.

So you say that the web browser control from the toolbox and
System.Windows.Forms.WebBrowser
are not the same?

In the components initialize page of my app it says

Me.web1 = New System.Windows.Forms.WebBrowser

Well, anyway, I solved my problem. I thank you all for your replies and tips.
 
M

mpetrotta

Thank you for the tip. Actually, I figured out a couple of things (btw, I
confess that I am really a vB guy and was studying a sample I found in C# -
forgot about the parens - lazy vb guy - the IDE puts em in for me). But I am
able to get the current url from the documentcompleted event of the web
browser.

So you say that the web browser control from the toolbox and
System.Windows.Forms.WebBrowser
are not the same?

I don't know what's in your toolbox, but if you're constructing it as
you described in your original post, then no, they're not the same.
System.Windows.Forms.WebBrowser does not have a Navigate2 method (it
has a Navigate method that takes far fewer arguments).
In the components initialize page of my app it says

Me.web1 = New System.Windows.Forms.WebBrowser

Then you're not using the same code or control as you posted
originally. You're now using the newer, more sensible control:

WebBrowser webBrowser = new WebBrowser();
webBrowser.Navigated += webBrowser_Navigated;
....
private void webBrowser_Navigated(object sender,
WebBrowserNavigatedEventArgs e)
{
Console.WriteLine(e.Url.ToString());
}
....
webBrowser.Navigate("http://www.google.com");
....

Note that you need to wait for the control to finish navigating before
you can retrieve the URL, as shown above.

Michael



Michael
 
M

mpetrotta

Back to your original issue: since you say you're using .NET 2.0, I
strongly suggest you use the native WebBrowser control
(System.Windows.Forms.WebBrowser) rather than the ActiveX-wrapped
kludge. It's more robust and easier to use.

("Native" is the wrong word - there's still an ActiveX control being
wrapped, but it's the Framework WebBrowser class doing the wrapping
for you.)

Michael
 
G

Guest

I see your point. the webbrowser control from the toolbox (VS2005) does not
have a Navigate2 property. I will use the SystemWindows.Forms.WebBrowsert.

Thanks for the tip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top